Browse Source

Add discrete templates for multicheckbox elements.

This will let people modify the HTML used for checkboxes without
effecting the rest of the FormHelper.
Mark Story 10 years ago
parent
commit
bf078aef75

+ 2 - 0
src/View/Helper/FormHelper.php

@@ -111,6 +111,8 @@ class FormHelper extends Helper
             'label' => '<label{{attrs}}>{{text}}</label>',
             'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>',
             'legend' => '<legend>{{text}}</legend>',
+            'multicheckboxTitle' => '<legend>{{text}}</legend>',
+            'multicheckboxWrapper' => '<fieldset{{attrs}}>{{content}}</fieldset>',
             'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
             'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
             'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',

+ 5 - 5
src/View/Widget/MultiCheckboxWidget.php

@@ -50,8 +50,8 @@ class MultiCheckboxWidget implements WidgetInterface
      * - `checkboxWrapper` Renders the containing div/element for
      *   a checkbox and its label. Accepts the `input`, and `label`
      *   variables.
-     * - `fieldset` Renders the fieldset for grouped inputs.
-     * - `legend` Renders the legend element for grouped inputs.
+     * - `multicheckboxWrapper` Renders a wrapper around grouped inputs.
+     * - `multicheckboxTitle` Renders the title element for grouped inputs.
      *
      * @param \Cake\View\StringTemplate $templates Templates list.
      * @param \Cake\View\Widget\LabelWidget $label Label widget instance.
@@ -127,9 +127,9 @@ class MultiCheckboxWidget implements WidgetInterface
             // Grouped inputs in a fieldset.
             if (is_string($key) && is_array($val) && !isset($val['text'], $val['value'])) {
                 $inputs = $this->_renderInputs(['options' => $val] + $data, $context);
-                $legend = $this->_templates->format('legend', ['text' => $key]);
-                $out[] = $this->_templates->format('fieldset', [
-                    'content' => $legend . implode('', $inputs)
+                $title = $this->_templates->format('multicheckboxTitle', ['text' => $key]);
+                $out[] = $this->_templates->format('multicheckboxWrapper', [
+                    'content' => $title . implode('', $inputs)
                 ]);
                 continue;
             }

+ 2 - 2
tests/TestCase/View/Widget/MultiCheckboxWidgetTest.php

@@ -37,8 +37,8 @@ class MultiCheckboxWidgetTest extends TestCase
             'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
             'label' => '<label{{attrs}}>{{text}}</label>',
             'checkboxWrapper' => '<div class="checkbox">{{input}}{{label}}</div>',
-            'fieldset' => '<fieldset{{attrs}}>{{content}}</fieldset>',
-            'legend' => '<legend>{{text}}</legend>',
+            'multicheckboxWrapper' => '<fieldset{{attrs}}>{{content}}</fieldset>',
+            'multicheckboxTitle' => '<legend>{{text}}</legend>',
         ];
         $this->templates = new StringTemplate($templates);
         $this->context = $this->getMock('Cake\View\Form\ContextInterface');