Skip to content

Commit

Permalink
Coding standards cleanup.
Browse files Browse the repository at this point in the history
Fix coding standards
Simplify addition of empty.
Add doc block for new feature.
  • Loading branch information
markstory committed Apr 7, 2012
1 parent 613e382 commit 38b7ae3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
38 changes: 15 additions & 23 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -3558,15 +3558,12 @@ public function testRadioHiddenInputDisabling() {
* @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
)
);
'type' => 'radio',
'options' => array('option A'),
'empty' => true,
'hiddenField' => false
));
$expected = array(
'div' => array('class' => 'input radio'),
'fieldset' => array(),
Expand All @@ -3586,14 +3583,12 @@ public function testRadioAddEmptyOption() {
);
$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
)
);
'type' => 'radio',
'options' => array('option A'),
'empty' => 'CustomEmptyLabel',
'hiddenField' => false
));
$expected = array(
'div' => array('class' => 'input radio'),
'fieldset' => array(),
Expand All @@ -3613,16 +3608,13 @@ public function testRadioAddEmptyOption() {
);
$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
)
);
'type' => 'radio',
'options' => array('option A'),
'empty' => false,
'hiddenField' => false
));
$this->assertTextNotContains('"Model1Field"', $result);

}

/**
Expand Down
10 changes: 4 additions & 6 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1343,6 +1343,8 @@ public function checkbox($fieldName, $options = array()) {
* - `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.
Expand All @@ -1356,9 +1358,7 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
$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']);

Expand Down Expand Up @@ -1894,9 +1894,7 @@ public function select($fieldName, $options = array(), $attributes = array()) {

if ($emptyMulti) {
$showEmpty = ($showEmpty === true) ? '' : $showEmpty;
$options = array_reverse($options, true);
$options[''] = $showEmpty;
$options = array_reverse($options, true);
$options = array('' => $showEmpty) + $options;
}

if (!$id) {
Expand Down

0 comments on commit 38b7ae3

Please sign in to comment.