Permalink
Browse files

Fixed issue where FormHelper::radio() and FormHelper::select() with o…

…ption "multiple"=>"checkbox" would generate tag with invalid "id" attribute if a value was non alphanumeric
  • Loading branch information...
1 parent 0d86302 commit 62161203f29283b7eae57483171c94c75aec4ffe @ADmad ADmad committed Oct 10, 2010
Showing with 29 additions and 7 deletions.
  1. +4 −4 cake/libs/view/helpers/form.php
  2. +25 −3 cake/tests/cases/libs/view/helpers/form.test.php
@@ -589,7 +589,7 @@ function label($fieldName = null, $text = null, $options = array()) {
*
* In addition to fields control, inputs() allows you to use a few additional options.
*
- * - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
+ * - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
* the classname for the fieldset element.
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
* to customize the legend text.
@@ -1090,7 +1090,7 @@ function radio($fieldName, $options = array(), $attributes = array()) {
array('name', 'type', 'id'), '', ' '
);
$tagName = Inflector::camelize(
- $attributes['id'] . '_' . Inflector::underscore($optValue)
+ $attributes['id'] . '_' . Inflector::slug($optValue)
);
if ($label) {
@@ -1778,7 +1778,7 @@ function meridian($fieldName, $selected = null, $attributes = array()) {
* - `separator` The contents of the string between select elements. Defaults to '-'
* - `empty` - If true, the empty select option is shown. If a string,
* that string is displayed as the empty element.
- * - `value` | `default` The default value to be used by the input. A value in `$this->data`
+ * - `value` | `default` The default value to be used by the input. A value in `$this->data`
* matching the field name will override this value. If no default is provided `time()` will be used.
*
* @param string $fieldName Prefix name for the SELECT element
@@ -2033,7 +2033,7 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
$htmlOptions['value'] = $name;
$tagName = Inflector::camelize(
- $this->model() . '_' . $this->field().'_'.Inflector::underscore($name)
+ $this->model() . '_' . $this->field().'_'.Inflector::slug($name)
);
$htmlOptions['id'] = $tagName;
$label = array('for' => $tagName);
@@ -1865,7 +1865,7 @@ function testInputCheckbox() {
'/div'
);
$this->assertTags($result, $expected);
-
+
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
$expected = array(
'div' => array('class' => 'input checkbox'),
@@ -2502,6 +2502,18 @@ function testSelectAsCheckbox() {
'/div',
);
$this->assertTags($result, $expected);
+
+ $result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), null, array('multiple' => 'checkbox'));
+ $expected = array(
+ 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
+ array('div' => array('class' => 'checkbox')),
+ array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
+ array('label' => array('for' => 'ModelMultiField12')),
+ 'half',
+ '/label',
+ '/div',
+ );
+ $this->assertTags($result, $expected);
}
/**
@@ -2691,6 +2703,16 @@ function testRadio() {
);
$this->assertTags($result, $expected);
+ $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'),
+ 'half',
+ '/label'
+ );
+ $this->assertTags($result, $expected);
+
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
$expected = array(
'fieldset' => array(),
@@ -3476,7 +3498,7 @@ function testSelectMultipleCheckboxSecurity() {
*/
function testInputMultipleCheckboxes() {
$result = $this->Form->input('Model.multi_field', array(
- 'options' => array('first', 'second', 'third'),
+ 'options' => array('first', 'second', 'third'),
'multiple' => 'checkbox'
));
$expected = array(
@@ -3559,7 +3581,7 @@ function testInputMultipleCheckboxes() {
$result = $this->Form->input('Model.multi_field', array(
'options' => array('2' => 'second'),
'multiple' => 'checkbox',
- 'label' => false,
+ 'label' => false,
'div' => false
));
$expected = array(

0 comments on commit 6216120

Please sign in to comment.