public function render(array $data, ContextInterface $context)
 {
     $this->_View->Html->css('Garderobe/BootstrapKit.select2/select2.min.css', ['block' => true]);
     $this->_View->Html->css('Garderobe/BootstrapKit.select2/select2-bootstrap.css', ['block' => true]);
     $this->_View->Html->script('Garderobe/BootstrapKit.select2/select2.min.js', ['block' => true]);
     $js = "\n        \$(function(){\n            \$('.select2-input').select2({\n                theme: 'bootstrap'\n            });\n        });\n        ";
     $this->_View->Html->scriptBlock($js, ['block' => true]);
     if (!isset($data['class'])) {
         $data['class'] = 'select2-input';
     } else {
         $data['class'] .= ' select2-input';
     }
     return parent::render($data, $context);
 }
 /**
  * @see Cake\View\Widget\Checkbox::render();
  */
 public function render(array $data, ContextInterface $context)
 {
     if (!empty($data['label'])) {
         $label = $this->_label->render(['text' => $data['label']], $context);
     }
     unset($data['label']);
     if (!isset($data['class'])) {
         $data['class'] = '';
     }
     $data['class'] .= ' form-control';
     $select = parent::render($data, $context);
     if (!isset($label)) {
         return $this->_templates->format('selectWrapperNoLabel', ['input' => $select]);
     }
     return $this->_templates->format('selectWrapper', ['label' => $label, 'input' => $select]);
 }
 public function render(array $data, \Cake\View\Form\ContextInterface $context)
 {
     $values = [];
     if ($context->val('languages')) {
         foreach ($context->val('languages') as $language) {
             if (is_object($language)) {
                 $values[] = $language->id;
             } else {
                 $values[] = $language;
             }
         }
         $data['val'] = $values;
     }
     $data['type'] = 'select';
     return parent::render($data, $context);
 }
 /**
  * test render with null options
  *
  * @return void
  */
 public function testRenderNullOptions()
 {
     $select = new SelectBoxWidget($this->templates);
     $data = ['id' => 'BirdName', 'name' => 'Birds[name]', 'options' => null];
     $result = $select->render($data, $this->context);
     $expected = ['select' => ['name' => 'Birds[name]', 'id' => 'BirdName'], '/select'];
     $this->assertHtml($expected, $result);
     $data['empty'] = true;
     $result = $select->render($data, $this->context);
     $expected = ['select' => ['name' => 'Birds[name]', 'id' => 'BirdName'], ['option' => ['value' => '']], '/option', '/select'];
     $this->assertHtml($expected, $result);
     $data['empty'] = 'empty';
     $result = $select->render($data, $this->context);
     $expected = ['select' => ['name' => 'Birds[name]', 'id' => 'BirdName'], ['option' => ['value' => '']], 'empty', '/option', '/select'];
     $this->assertHtml($expected, $result);
 }
示例#5
0
 /**
  * Generates a meridian select
  *
  * @param array $options The options to generate a meridian select with.
  * @param \Cake\View\Form\ContextInterface $context The current form context.
  * @return string
  */
 protected function _meridianSelect($options, $context)
 {
     $options += ['name' => '', 'val' => null, 'options' => ['am' => 'am', 'pm' => 'pm']];
     return $this->_select->render($options, $context);
 }
 /**
  * Ensure templateVars option is hooked up.
  *
  * @return void
  */
 public function testRenderTemplateVars()
 {
     $this->templates->add(['select' => '<select custom="{{custom}}" name="{{name}}"{{attrs}}>{{content}}</select>', 'option' => '<option opt="{{opt}}" value="{{value}}"{{attrs}}>{{text}}</option>']);
     $input = new SelectBoxWidget($this->templates);
     $data = ['templateVars' => ['custom' => 'value', 'opt' => 'option'], 'name' => 'birds', 'options' => [['value' => 'a', 'text' => 'Albatross', 'templateVars' => ['opt' => 'opt-1']], 'b' => 'Budgie', 'c' => 'Canary']];
     $result = $input->render($data, $this->context);
     $expected = ['select' => ['name' => 'birds', 'custom' => 'value'], ['option' => ['value' => 'a', 'opt' => 'opt-1']], 'Albatross', '/option', ['option' => ['value' => 'b', 'opt' => 'option']], 'Budgie', '/option', ['option' => ['value' => 'c', 'opt' => 'option']], 'Canary', '/option', '/select'];
     $this->assertHtml($expected, $result);
 }
示例#7
0
 /**
  * Render the contents of the select element.
  *
  * `$data['options']` is expected to be associative array of regions for which
  * you want identifiers list. The key will be used as optgroup.
  * Eg. `['Asia' => DateTimeZone::ASIA, 'Europe' => DateTimeZone::EUROPE]`
  *
  * @param array $data The context for rendering a select.
  *
  * @return array
  */
 protected function _renderContent($data)
 {
     $data['options'] = $this->_identifierList($data['options']);
     return parent::_renderContent($data);
 }
示例#8
0
 /**
  * Render a select box form input.
  *
  * Render a select box input given a set of data. Supported keys
  * are:
  *
  * - `name` - Set the input name.
  * - `options` - An array of options.
  * - `disabled` - Either true or an array of options to disable.
  *    When true, the select element will be disabled.
  * - `val` - Either a string or an array of options to mark as selected.
  * - `empty` - Set to true to add an empty option at the top of the
  *   option elements. Set to a string to define the display text of the
  *   empty option. If an array is used the key will set the value of the empty
  *   option while, the value will set the display text.
  * - `escape` - Set to false to disable HTML escaping.
  *
  * ### Options format
  *
  * The options option can take a variety of data format depending on
  * the complexity of HTML you want generated.
  *
  * You can generate simple options using a basic associative array:
  *
  * ```
  * 'options' => ['elk' => 'Elk', 'beaver' => 'Beaver']
  * ```
  *
  * If you need to define additional attributes on your option elements
  * you can use the complex form for options:
  *
  * ```
  * 'options' => [
  *   ['value' => 'elk', 'text' => 'Elk', 'data-foo' => 'bar'],
  * ]
  * ```
  *
  * This form **requires** that both the `value` and `text` keys be defined.
  * If either is not set options will not be generated correctly.
  *
  * If you need to define option groups you can do those using nested arrays:
  *
  * ```
  * 'options' => [
  *  'Mammals' => [
  *    'elk' => 'Elk',
  *    'beaver' => 'Beaver'
  *  ]
  * ]
  * ```
  *
  * And finally, if you need to put attributes on your optgroup elements you
  * can do that with a more complex nested array form:
  *
  * ```
  * 'options' => [
  *   [
  *     'text' => 'Mammals',
  *     'data-id' => 1,
  *     'options' => [
  *       'elk' => 'Elk',
  *       'beaver' => 'Beaver'
  *     ]
  *  ],
  * ]
  * ```
  *
  * You are free to mix each of the forms in the same option set, and
  * nest complex types as required.
  *
  * @param array $data Data to render with.
  * @param \Cake\View\Form\ContextInterface $context The current form context.
  * @return string A generated select box.
  * @throws \RuntimeException when the name attribute is empty.
  */
 public function render(array $data, ContextInterface $context)
 {
     $data = $this->injectClasses('form-control', $data);
     return parent::render($data, $context);
 }