Issue Type: Bug Created: 2009-05-18T08:06:53.000+0000 Last Updated: 2012-11-20T21:37:42.000+0000 Status: Open Fix version(s): Reporter: Steven Bakhtiari (stevebakh) Assignee: None Tags: - Zend_Form
Related issues: Attachments:
It appeas that labels associated with individual radio button items have an id that is generated from the radio-set name (rating) and the value of each individual radio button. In the example below, you will see the values range from negative to positive values. Because of the way the id is generated, we will end up with duplicate elements sharing the same id. This not only breaks validation, but also usability, as clicking on a label no longer selects the expected radio button, as it should do.
There are ways around this from a developers perspective, Bittarman in IRC suggested adding a fixed number to each of the values and subtracting them after form submission. Personally, I find that a dirty hack that should be avoided. I could also choose different values for my radios, but again, the values here match what is expected in the application and the database, writing some means of converting them before saving them seems wrong too.
Perhaps, if we don't change the way the id's are generated by default, we could have an array which keeps a list of the id's already generated for a form and if a new id is generated that matches an existing id, we could append the id, perhaps starting up the alphabet.
 In fact, because the label's encompass the radio form element, we do not even need the for attribute. Labels automatically point to the encompassed element when selected.
[one more edit!] I have also just noticed that the main label, set when doing $rating->setLabel('Rating') has a for attribute which has a non-existing id set. This also causes validation to fail, so preferably, there should be no for attribute here.
<pre class="highlight"> $rating = new Zend_Form_Element_Radio('rating'); $rating->setLabel('Rating')->addMultiOptions(array( -2 => 'very bad', -1 => 'bad', 0 => 'indifferent', 1 => 'good', 2 => 'very good' ));
Posted by Simon Corless (sico) on 2010-12-09T00:37:15.000+0000
This is also related to this issue: http://framework.zend.com/issues/browse/ZF-4191
You will see in this bug report it's to do with the filter applied to option values when creating the ids/.
I have unfortunately come across this little issue this morning although it appears to have been an issue since the radio elements release.
Have you found an issue?
See the Overview section for more details.