Skip to content

Commit

Permalink
Add discrete templates for multicheckbox elements.
Browse files Browse the repository at this point in the history
This will let people modify the HTML used for checkboxes without
effecting the rest of the FormHelper.
  • Loading branch information
markstory committed Mar 6, 2016
1 parent 709b54e commit bf078ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/View/Helper/FormHelper.php
Expand Up @@ -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>',
Expand Down
10 changes: 5 additions & 5 deletions src/View/Widget/MultiCheckboxWidget.php
Expand Up @@ -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.
Expand Down Expand Up @@ -127,9 +127,9 @@ protected function _renderInputs($data, $context)
// 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;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/View/Widget/MultiCheckboxWidgetTest.php
Expand Up @@ -37,8 +37,8 @@ public function setUp()
'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');
Expand Down

0 comments on commit bf078ae

Please sign in to comment.