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
*/
public function testRadioAddEmptyOption() {
// $options['empty'] = true
$result = $this->Form->input('Model.1.field', array(
'type' => 'radio',
'options' => array('option A'),
'empty' => true,
'hiddenField' => false
)
);
));
$expected = array(
'div' => array('class' => 'input radio'),
'fieldset' => array(),
@ -3586,14 +3583,12 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
// $options['empty'] = 'CustomEmptyLabel'
$result = $this->Form->input('Model.1.field', array(
'type' => 'radio',
'options' => array('option A'),
'empty' => 'CustomEmptyLabel',
'hiddenField' => false
)
);
));
$expected = array(
'div' => array('class' => 'input radio'),
'fieldset' => array(),
@ -3613,16 +3608,13 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
// $options['empty'] = false
$result = $this->Form->input('Model.1.field', array(
'type' => 'radio',
'options' => array('option A'),
'empty' => false,
'hiddenField' => false
)
);
));
$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
* 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.
* - `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 array $options Radio button options array.
@ -1356,9 +1358,7 @@ class FormHelper extends AppHelper {
$showEmpty = $this->_extractOption('empty', $attributes);
if ($showEmpty) {
$showEmpty = ($showEmpty === true) ? __('empty') : $showEmpty;
$options = array_reverse($options, true);
$options[''] = $showEmpty;
$options = array_reverse($options, true);
$options = array('' => $showEmpty) + $options;
}
unset($attributes['empty']);
@ -1894,9 +1894,7 @@ class FormHelper extends AppHelper {
if ($emptyMulti) {
$showEmpty = ($showEmpty === true) ? '' : $showEmpty;
$options = array_reverse($options, true);
$options[''] = $showEmpty;
$options = array_reverse($options, true);
$options = array('' => $showEmpty) + $options;
}
if (!$id) {