/** * Test render with additional attributes. * * @return void */ public function testRenderAttributes() { $text = new BasicWidget($this->templates); $data = ['name' => 'my_input', 'type' => 'email', 'class' => 'form-control', 'required' => true]; $result = $text->render($data, $this->context); $expected = ['input' => ['type' => 'email', 'name' => 'my_input', 'class' => 'form-control', 'required' => 'required']]; $this->assertHtml($expected, $result); }
/** * Render a text widget or other simple widget like email/tel/number. * * This method accepts a number of keys: * * - `name` The name attribute. * - `val` The value attribute. * - `escape` Set to false to disable escaping on all attributes. * - `append` Append addon to input. * - `prepend` Prepend addon to input. * * Any other keys provided in $data will be converted into HTML attributes. * * @param array $data The data to build an input with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string */ public function render(array $data, ContextInterface $context) { $data += ['prepend' => null, 'append' => null]; $input = $this->_templates->get('input'); if ($data['prepend']) { if (is_string($data['prepend'])) { $class = 'input-group-' . ($this->_isButton($data['prepend']) ? 'btn' : 'addon'); $input = '<span class="' . $class . '">' . $data['prepend'] . '</span>' . $input; } else { $class = 'input-group-btn'; $input = '<span class="' . $class . '">' . implode('', $data['prepend']) . '</span>' . $input; } } if ($data['append']) { if (is_string($data['append'])) { $class = 'input-group-' . ($this->_isButton($data['append']) ? 'btn' : 'addon'); $input .= '<span class="' . $class . '">' . $data['append'] . '</span>'; } else { $class = 'input-group-btn'; $input .= '<span class="' . $class . '">' . implode('', $data['append']) . '</span>'; } } if ($data['prepend'] || $data['append']) { $input = '<div class="input-group">' . $input . '</div>'; $this->_templates->add(compact('input')); } unset($data['append'], $data['prepend']); return parent::render($data, $context); }
public function render(array $data, ContextInterface $context) { $idPicker = $data['id'] . '_dtPicker'; $this->_templates->add(['label' => '<label class="col-md-3 control-label"{{attrs}}>{{text}}</label>']); $this->_templates->add(['input' => '<div class="col-md-8"><div class="input-group date" id="' . $idPicker . '"><span class="input-group-addon cursor"><i class="fa fa-calendar"></i></span><input type="text" name="{{name}}"{{attrs}}></div></div>']); return parent::render($data, $context); }
/** * Render a text widget or other simple widget like email/tel/number. * * This method accepts a number of keys: * * - `name` The name attribute. * - `val` The value attribute. * - `escape` Set to false to disable escaping on all attributes. * - `append` Append addon to input. * - `prepend` Prepend addon to input. * * Any other keys provided in $data will be converted into HTML attributes. * * @param array $data The data to build an input with. * @param \Cake\View\Form\ContextInterface $context The current form context. * @return string */ public function render(array $data, ContextInterface $context) { $data += ['prepend' => null, 'append' => null]; $prepend = $data['prepend']; $append = $data['append']; unset($data['append'], $data['prepend']); $input = parent::render($data, $context); if ($prepend) { $prepend = $this->_addon($prepend, $data); } if ($append) { $append = $this->_addon($append, $data); } if ($prepend || $append) { $input = $this->_templates->format('inputGroupContainer', ['append' => $append, 'prepend' => $prepend, 'content' => $input, 'templateVars' => $data['templateVars']]); } return $input; }
/** * Test render with template params. * * @return void */ public function testRenderTemplateParams() { $text = new BasicWidget(new StringTemplate(['input' => '<input type="{{type}}" name="{{name}}"{{attrs}}><span>{{help}}</span>'])); $data = ['name' => 'my_input', 'type' => 'email', 'class' => 'form-control', 'required' => true, 'templateVars' => ['help' => 'SOS']]; $result = $text->render($data, $this->context); $expected = ['input' => ['type' => 'email', 'name' => 'my_input', 'class' => 'form-control', 'required' => 'required'], '<span', 'SOS', '/span']; $this->assertHtml($expected, $result); }
/** * @see Cake\View\Widget\Checkbox::render(); */ public function render(array $data, ContextInterface $context) { return parent::render($data, $context); }