Skip to content
Permalink
Browse files

Add discrete templates for multicheckbox elements.

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 bf078aef75f77cb42e2913d5f836e9edc0e03ddd
@@ -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>',
@@ -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 @@ 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;
}
@@ -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');

0 comments on commit bf078ae

Please sign in to comment.
You can’t perform that action at this time.