Zend Framework

Zend_View_Helper_FormRadio generates improper id attributes for certain values

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.0
  • Fix Version/s: 1.11.8
  • Component/s: Zend_Form, Zend_View
  • Labels:
    None

Description

$form = new Zend_Form();
$form->addElement('radio', 'myName', array(
'value' => '-1',
'multiOptions' => array(
'inherit' => 'inherit',
-1 => 'reset',
1 => 'allow',
0 => 'deny',
),
));
$form->populate(array('myName' => 'inherit'));
echo $form;

Generated xhtml:

<label style="white-space: nowrap;">
<input type="radio" name="myName" id="myName-inherit" value="inherit" checked="checked" />inherit
</label><br />
<label style="white-space: nowrap;">
<input type="radio" name="myName" id="myName-1" value="-1" />reset
</label><br />
<label style="white-space: nowrap;">
<input type="radio" name="myName" id="myName-1" value="1" />allow
</label><br />
<label style="white-space: nowrap;">
<input type="radio" name="myName" id="myName-0" value="0" checked="checked" />deny
</label>

has two elements with same id "myName-1" (options "-1" and "1"). Also "0 => 'deny'" option is selected, but I have populated form with "'myName' => 'inherit'". Also "0 => 'deny'" option will be selected by default, but I set default "'value' => '-1'".

  1. 4191.diff
    22/Dec/08 1:31 PM
    2 kB
    Joeri Sebrechts
  2. ZF-4191.patch
    28/May/11 4:36 PM
    2 kB
    Adam Lundrigan

Activity

Hide
Joeri Sebrechts added a comment -

Patch to fix the issue. The problem was that dashes were filtered from the id through the use of the alnum filter. In the patch a regex is used to allow both alphanumeric characters and dashes.

Show
Joeri Sebrechts added a comment - Patch to fix the issue. The problem was that dashes were filtered from the id through the use of the alnum filter. In the patch a regex is used to allow both alphanumeric characters and dashes.
Hide
Simon Corless added a comment -

Is there any chance of getting this fixed or adding the patch to trunk?

Show
Simon Corless added a comment - Is there any chance of getting this fixed or adding the patch to trunk?
Hide
Adam Lundrigan added a comment -

Tidied suggested fix and added more thorough unit test

Show
Adam Lundrigan added a comment - Tidied suggested fix and added more thorough unit test
Hide
Adam Lundrigan added a comment -

Fixed in trunk r24059

Show
Adam Lundrigan added a comment - Fixed in trunk r24059
Hide
Adam Lundrigan added a comment -

I've hesitated to merge this into release as it may cause a BC break for those who reference their Zend_Form elements by id from a view script. Thoughts?

Show
Adam Lundrigan added a comment - I've hesitated to merge this into release as it may cause a BC break for those who reference their Zend_Form elements by id from a view script. Thoughts?
Hide
Kim Blomqvist added a comment -

I would patch this.

Show
Kim Blomqvist added a comment - I would patch this.
Hide
Adam Lundrigan added a comment -

Merged to release-1.11 in r24160

Show
Adam Lundrigan added a comment - Merged to release-1.11 in r24160

People

Vote (5)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: