contributte / forms-bootstrap

👾 Bootstrap 4 + 5 forms for Nette framework
MIT License
19 stars 19 forks source link

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

Closed frosty22 closed 7 months ago

frosty22 commented 7 months ago

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 commented 7 months ago

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

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