contributte / forms-bootstrap

👾 Bootstrap 4 + 5 forms for Nette framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

frosty22 opened this issue · 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.

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

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