Permalink
Browse files

Also make DOM ids for radio element values unique.

  • Loading branch information...
dereuromark committed Dec 4, 2013
1 parent 587a04a commit 8ebf004450778023924a70502c0537ba34ba6029
Showing with 36 additions and 5 deletions.
  1. +34 −2 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +2 −3 lib/Cake/View/Helper/FormHelper.php
@@ -3503,8 +3503,8 @@ public function testRadio() {
$result = $this->Form->radio('Model.field', array('1/2' => 'half'));
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')),
'label' => array('for' => 'ModelField12'),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField1/2')),
'label' => array('for' => 'ModelField1/2'),
'half',
'/label'
);
@@ -3631,6 +3631,38 @@ public function testRadio() {
'/fieldset'
);
$this->assertTags($result, $expected);
$result = $this->Form->radio(
'Model.field',
array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third')
);
$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][field]',
'id' => 'ModelField_', 'value' => '',
),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
'id' => 'ModelFieldAB', 'value' => 'a&gt;b')),
array('label' => array('for' => 'ModelFieldAB')),
'first',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
'id' => 'ModelFieldAB1', 'value' => 'a&lt;b')),
array('label' => array('for' => 'ModelFieldAB1')),
'second',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
'id' => 'ModelFieldAB2', 'value' => 'a&quot;b')),
array('label' => array('for' => 'ModelFieldAB2')),
'third',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);
}
/**
@@ -1514,6 +1514,7 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
$value = $value ? 1 : 0;
}
$this->_domIdSuffixes = array();
foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue, 'disabled' => false);
@@ -1524,9 +1525,7 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
if ($disabled && (!is_array($disabled) || in_array((string)$optValue, $disabled, !$isNumeric))) {
$optionsHere['disabled'] = true;
}
$tagName = Inflector::camelize(
$attributes['id'] . '_' . Inflector::slug($optValue)
);
$tagName = $attributes['id'] . $this->domIdSuffix($optValue);
if ($label) {
$labelOpts = is_array($label) ? $label : array();

0 comments on commit 8ebf004

Please sign in to comment.