Browse Source

Move checkbox hidden field outside of the nested label

Walther Lalk 11 years ago
parent
commit
e9e0697601
2 changed files with 15 additions and 5 deletions
  1. 12 4
      src/View/Helper/FormHelper.php
  2. 3 1
      src/View/Widget/LabelWidget.php

+ 12 - 4
src/View/Helper/FormHelper.php

@@ -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>',
@@ -769,6 +769,9 @@ class FormHelper extends Helper {
 			'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);
@@ -1298,17 +1301,22 @@ class FormHelper extends Helper {
 
 		$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);
 	}

+ 3 - 1
src/View/Widget/LabelWidget.php

@@ -72,13 +72,15 @@ class LabelWidget implements WidgetInterface {
 		$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']),
 		]);
 	}