Skip to content

Commit

Permalink
Only split hidden field by default if checkbox is being called from t…
Browse files Browse the repository at this point in the history
…he input() method
  • Loading branch information
Walther Lalk committed Nov 6, 2014
1 parent e9e0697 commit 222fc2b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/View/Helper/FormHelper.php
Expand Up @@ -958,6 +958,10 @@ public function input($fieldName, array $options = []) {
}
$nestedInput = isset($options['nestedInput']) ? $options['nestedInput'] : $nestedInput;

if ($nestedInput == true && $options['type'] === 'checkbox' && !array_key_exists('hiddenField', $options) && $label !== false) {
$options['hiddenField'] = '_split';
}

$input = $this->_getInput($fieldName, $options);
if ($options['type'] === 'hidden') {
if ($newTemplates) {
Expand Down Expand Up @@ -1287,11 +1291,11 @@ protected function _inputLabel($fieldName, $label, $options) {
*
* @param string $fieldName Name of a field, like this "Modelname.fieldname"
* @param array $options Array of HTML attributes.
* @return string An HTML text input element.
* @return string|array An HTML text input element.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
*/
public function checkbox($fieldName, array $options = []) {
$options += array('hiddenField' => true, 'value' => 1);
$options += ['hiddenField' => true, 'value' => 1];

// Work around value=>val translations.
$value = $options['value'];
Expand All @@ -1313,7 +1317,7 @@ public function checkbox($fieldName, array $options = []) {
$output = $this->hidden($fieldName, $hiddenOptions);
}

if ($options['hiddenField'] == '_split') {
if ($options['hiddenField'] === '_split') {
unset($options['hiddenField'], $options['type']);
return ['hidden' => $output, 'input' => $this->widget('checkbox', $options)];
}
Expand Down

0 comments on commit 222fc2b

Please sign in to comment.