forms-bootstrap icon indicating copy to clipboard operation
forms-bootstrap copied to clipboard

How to set setHtmlId for pair (label + input) for support toggle?

Open frosty22 opened this issue 2 years ago • 1 comments

Hello, I have a question about toggle support. Is it possible to set the id for the pair (label + input) combination?

Currently when using the "setHtmlId" function, the given id is set only for the given control, which will be insufficient in most cases. Alternatively, there is some option like getPairPrototype() or getPairPart(), similar to the getControlPart/getLabelPart methods.

Unfortunately, this is the only limitation for simply rendering the form completely instead of manually rendering it. Using function toggle is very common for me.

Example - part form:

		$form->addRadioList('type', 'Type', [
			1 => 'URL',
                        // ......
		])->setDefaultValue(1)
			->addCondition($form::Equal, 1)
			->toggle('id-type-1');

		$form->addText('url', 'URL')
			->setHtmlId('id-type-1');

Part of rendered form:

<div class="mb-3" id="HOW-SET-ID-HERE?">
	<label for="id-type-1" class="form-label">URL obrázku</label>
	<textarea name="thumbnail" rows="2" id="id-type-1" class="form-control" style=""></textarea>
</div>

I looking for a way, how to se ID to pair (without manual rendering).

Thanks for any help.

frosty22 avatar Apr 03 '24 10:04 frosty22

I found it ... setHtmlId not working but setOption yes:

	$form->addText('url', 'URL')
			->setOption('id', 'id-type-1');

frosty22 avatar Apr 04 '24 23:04 frosty22