Skip to content

Commit

Permalink
Move checkbox hidden field outside of the nested label
Browse files Browse the repository at this point in the history
  • Loading branch information
Walther Lalk committed Nov 6, 2014
1 parent ec4b386 commit e9e0697
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/View/Helper/FormHelper.php
Expand Up @@ -94,7 +94,7 @@ class FormHelper extends Helper {
'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>',
'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>',
'label' => '<label{{attrs}}>{{text}}</label>',
'nestingLabel' => '<label{{attrs}}>{{input}}{{text}}</label>',
'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>',
'legend' => '<legend>{{text}}</legend>',
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
Expand Down Expand Up @@ -769,6 +769,9 @@ public function label($fieldName, $text = null, array $options = []) {
'text' => $text,
];
if (isset($options['input'])) {
if (is_array($options['input'])) {
$attrs = $options['input'] + $attrs;
}
return $this->widget('nestingLabel', $attrs);
}
return $this->widget('label', $attrs);
Expand Down Expand Up @@ -1298,17 +1301,22 @@ public function checkbox($fieldName, array $options = []) {

$output = '';
if ($options['hiddenField']) {
$hiddenOptions = array(
$hiddenOptions = [
'name' => $options['name'],
'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'),
'value' => ($options['hiddenField'] !== true && $options['hiddenField'] !== '_split' ? $options['hiddenField'] : '0'),
'form' => isset($options['form']) ? $options['form'] : null,
'secure' => false
);
];
if (isset($options['disabled']) && $options['disabled']) {
$hiddenOptions['disabled'] = 'disabled';
}
$output = $this->hidden($fieldName, $hiddenOptions);
}

if ($options['hiddenField'] == '_split') {
unset($options['hiddenField'], $options['type']);
return ['hidden' => $output, 'input' => $this->widget('checkbox', $options)];
}
unset($options['hiddenField'], $options['type']);
return $output . $this->widget('checkbox', $options);
}
Expand Down
4 changes: 3 additions & 1 deletion src/View/Widget/LabelWidget.php
Expand Up @@ -72,13 +72,15 @@ public function render(array $data, ContextInterface $context) {
$data += [
'text' => '',
'input' => '',
'hidden' => '',
'escape' => true,
];

return $this->_templates->format($this->_labelTemplate, [
'text' => $data['escape'] ? h($data['text']) : $data['text'],
'input' => $data['input'],
'attrs' => $this->_templates->formatAttributes($data, ['text', 'input']),
'hidden' => $data['hidden'],
'attrs' => $this->_templates->formatAttributes($data, ['text', 'input', 'hidden']),
]);
}

Expand Down

0 comments on commit e9e0697

Please sign in to comment.