Coding standards cleanup.

Fix coding standards
Simplify addition of empty.
Add doc block for new feature.
This commit is contained in:
mark_story 2012-04-06 21:46:34 -04:00
parent 613e3824e0
commit 38b7ae3c67
2 changed files with 19 additions and 29 deletions

View file

@ -3558,15 +3558,12 @@ class FormHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testRadioAddEmptyOption() { public function testRadioAddEmptyOption() {
// $options['empty'] = true
$result = $this->Form->input('Model.1.field', array( $result = $this->Form->input('Model.1.field', array(
'type' => 'radio', 'type' => 'radio',
'options' => array('option A'), 'options' => array('option A'),
'empty' => true, 'empty' => true,
'hiddenField' => false 'hiddenField' => false
) ));
);
$expected = array( $expected = array(
'div' => array('class' => 'input radio'), 'div' => array('class' => 'input radio'),
'fieldset' => array(), 'fieldset' => array(),
@ -3586,14 +3583,12 @@ class FormHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
// $options['empty'] = 'CustomEmptyLabel'
$result = $this->Form->input('Model.1.field', array( $result = $this->Form->input('Model.1.field', array(
'type' => 'radio', 'type' => 'radio',
'options' => array('option A'), 'options' => array('option A'),
'empty' => 'CustomEmptyLabel', 'empty' => 'CustomEmptyLabel',
'hiddenField' => false 'hiddenField' => false
) ));
);
$expected = array( $expected = array(
'div' => array('class' => 'input radio'), 'div' => array('class' => 'input radio'),
'fieldset' => array(), 'fieldset' => array(),
@ -3613,16 +3608,13 @@ class FormHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
// $options['empty'] = false
$result = $this->Form->input('Model.1.field', array( $result = $this->Form->input('Model.1.field', array(
'type' => 'radio', 'type' => 'radio',
'options' => array('option A'), 'options' => array('option A'),
'empty' => false, 'empty' => false,
'hiddenField' => false 'hiddenField' => false
) ));
);
$this->assertTextNotContains('"Model1Field"', $result); $this->assertTextNotContains('"Model1Field"', $result);
} }
/** /**

View file

@ -1343,6 +1343,8 @@ class FormHelper extends AppHelper {
* - `hiddenField` - boolean to indicate if you want the results of radio() to include * - `hiddenField` - boolean to indicate if you want the results of radio() to include
* a hidden input with a value of ''. This is useful for creating radio sets that non-continuous * a hidden input with a value of ''. This is useful for creating radio sets that non-continuous
* - `disabled` - Set to `true` or `disabled` to disable all the radio buttons. * - `disabled` - Set to `true` or `disabled` to disable all the radio buttons.
* - `empty` - Set to `true` to create a input with the value '' as the first option. When `true`
* the radio label will be 'empty'. Set this option to a string to control the label value.
* *
* @param string $fieldName Name of a field, like this "Modelname.fieldname" * @param string $fieldName Name of a field, like this "Modelname.fieldname"
* @param array $options Radio button options array. * @param array $options Radio button options array.
@ -1356,9 +1358,7 @@ class FormHelper extends AppHelper {
$showEmpty = $this->_extractOption('empty', $attributes); $showEmpty = $this->_extractOption('empty', $attributes);
if ($showEmpty) { if ($showEmpty) {
$showEmpty = ($showEmpty === true) ? __('empty') : $showEmpty; $showEmpty = ($showEmpty === true) ? __('empty') : $showEmpty;
$options = array_reverse($options, true); $options = array('' => $showEmpty) + $options;
$options[''] = $showEmpty;
$options = array_reverse($options, true);
} }
unset($attributes['empty']); unset($attributes['empty']);
@ -1894,9 +1894,7 @@ class FormHelper extends AppHelper {
if ($emptyMulti) { if ($emptyMulti) {
$showEmpty = ($showEmpty === true) ? '' : $showEmpty; $showEmpty = ($showEmpty === true) ? '' : $showEmpty;
$options = array_reverse($options, true); $options = array('' => $showEmpty) + $options;
$options[''] = $showEmpty;
$options = array_reverse($options, true);
} }
if (!$id) { if (!$id) {