public function render(array $data, ContextInterface $context) { $this->_View->Html->css('Garderobe/BootstrapKit.switch/bootstrap-switch.min.css', ['block' => true]); $this->_View->Html->script('Garderobe/BootstrapKit.switch/bootstrap-switch.min.js', ['block' => true]); $js = "\n \$(function(){\n \$('.bootstrap-switcher').bootstrapSwitch();\n });\n "; $this->_View->Html->scriptBlock($js, ['block' => true]); if (!isset($data['class'])) { $data['class'] = 'bootstrap-switcher'; } else { $data['class'] .= ' bootstrap-switcher'; } $hidden = ''; if (!isset($data['hiddenField'])) { $data['hiddenField'] = true; } if ($data['hiddenField'] != true || $data['hiddenField'] !== false) { $hiddenOptions = ['type' => 'hidden', 'name' => $data['name'], 'val' => $data['hiddenField'] !== true ? $data['hiddenField'] : '0', 'form' => isset($data['form']) ? $data['form'] : null, 'secure' => false]; if (isset($data['disabled']) && $data['disabled']) { $hiddenOptions['disabled'] = 'disabled'; } $hidden = $this->_hidden->render($hiddenOptions, $context); } unset($data['hiddenField']); return $hidden . parent::render($data, $context); }
/** * Render a checkbox element. * * Data supports the following keys: * * - `name` - The name of the input. * - `inline` - The alignement to use. * - `value` - The value attribute. Defaults to '1'. * - `val` - The current value. If it matches `value` the checkbox will be checked. * You can also use the 'checked' attribute to make the checkbox checked. * - `disabled` - Whether or not the checkbox should be disabled. * * Any other attributes passed in will be treated as HTML attributes. * * @param array $data The data to create a checkbox with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string Generated HTML string. */ public function render(array $data, ContextInterface $context) { $data += ['inline' => false]; if ($data['inline']) { $this->_templates->add(['checkboxContainer' => '{{content}}']); } unset($data['inline']); return parent::render($data, $context); }
/** * @see Cake\View\Widget\Checkbox::render(); */ public function render(array $data, ContextInterface $context) { $labelData['text'] = $data['label']; unset($data['label']); $checkbox = parent::render($data, $context); $labelData['text'] = $checkbox . $labelData['text']; $labelData['escape'] = false; $labeledCheckbox = $this->_label->render($labelData, $context); return $this->_templates->format('checkboxWrapper', ['checkbox' => $labeledCheckbox]); }
public function render(array $data, ContextInterface $context) { $data['value'] = $data['val']; $data['class'] = $this->_generateFieldClass('ft-bootstrap-switch', $data['name']); $ftOptions = isset($data['ftOptions']) ? $data['ftOptions'] : []; unset($data['ftOptions']); unset($data['col']); // Script/styles include echo $this->_View->Html->script('FieldTypes.../vendor/bootstrap-switch/dist/js/bootstrap-switch.min.js', ['block' => 'headjs']); echo $this->_View->Html->css('FieldTypes.../vendor/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.css', ['block' => 'css']); echo $this->_View->Html->css('FieldTypes.switch.css', ['block' => 'css']); // Script call $this->_View->Html->scriptStart(['block' => true]); echo '$(document).ready(function() { $(".' . $data['class'] . '").bootstrapSwitch(' . json_encode($ftOptions, true) . '); });'; $this->_View->Html->scriptEnd(); return parent::render($data, $context); }
/** * Test rendering unchecked checkboxes * * @dataProvider uncheckedProvider * @return void */ public function testRenderUnCheckedValue($checked) { $checkbox = new CheckboxWidget($this->templates); $data = ['name' => 'Comment[spam]', 'value' => 1, 'val' => 1, 'checked' => $checked]; $result = $checkbox->render($data, $this->context); $expected = ['input' => ['type' => 'checkbox', 'name' => 'Comment[spam]', 'value' => 1]]; $this->assertHtml($expected, $result); }
/** * Ensure templateVars option is hooked up. * * @return void */ public function testRenderTemplateVars() { $this->templates->add(['checkbox' => '<input type="checkbox" custom="{{custom}}" name="{{name}}" value="{{value}}"{{attrs}}>']); $checkbox = new CheckboxWidget($this->templates); $data = ['templateVars' => ['custom' => 'value'], 'name' => 'Comment[spam]', 'value' => 1]; $result = $checkbox->render($data, $this->context); $expected = ['input' => ['type' => 'checkbox', 'custom' => 'value', 'name' => 'Comment[spam]', 'value' => 1]]; $this->assertHtml($expected, $result); }