zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

Accessing fieldset and legend for radio buttons #129

Open automatix opened 8 years ago

automatix commented 8 years ago

An element's label can get attributes, e.g. class. Theoretically this behavior is also possible for radio buttons. But the setLabelAttributes(['class' => 'my_class']) called on a Zend\Form\Element\Radio object sets the attribute(-s) for the input elements and not for the container-element.

And it's not possible to access the fieldset or the legend element, that are "hard-coded" in the Zend\Form\View\Helper\FormRow. (Also the maintaining of a custom view helper for the 135 rows long FormRow#render(...) is not easy.)

It would be nice to be able to set the fieldset's and legend's attributes of radio buttons / multi_checkbox'es (and generally of all elements, affected by this code).

An example of a situation, when it's need, is makring elements as required using the :before CSS pseudo-class. For text fields it can be managed by setting the class attribute for the label. For radio's an access to the fieldset and/or at least to the legend is needed.

dennis-fedco commented 5 years ago

There appears to be no way to add attributes, such as an id to the generated fieldset that gets created for Element\Radio button, when ['options']['label'] value is used. I can add attributes to the individual <label> tags, or to the individual <input> tags, but not to the enveloping <fieldset> tag.
Currently, I used CSS selectors/pseudo-classes to get around this issue.

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at https://github.com/laminas/laminas-form/issues/20.