addMultiSelect() публичный Метод

Adds select box control that allows multiple item selection.
public addMultiSelect ( $name, $label = NULL, array $items = NULL, $size = NULL ) : MultiSelectBox
$items array
Результат Nette\Forms\Controls\MultiSelectBox
Пример #1
0
 /**
  * @param Nette\Forms\Container $container
  * @param string                $key
  * @param string                $name
  * @param array                $options
  * @return Nette\Forms\Controls\SelectBox
  */
 protected function addControl(Nette\Forms\Container $container, $key, $name, $options)
 {
     /**
      * Set some translated texts
      */
     $form = $container->lookup('Nette\\Application\\UI\\Form');
     $t = [$form->getTranslator(), 'translate'];
     $this->addAttribute('title', $t('ublaboo_datagrid.multiselect_choose'));
     $this->addAttribute('data-i18n-selected', $t('ublaboo_datagrid.multiselect_selected'));
     /**
      * Add input to container
      */
     $input = $container->addMultiSelect($key, $name, $options);
     return $this->addAttributes($input);
 }
Пример #2
0
 /**
  * @param  Container  $form
  * @return \Nette\Forms\IControl|NULL
  * @throws Exception
  */
 public function createInput(Container $form)
 {
     $name = $this->getName();
     $input = NULL;
     $items = [];
     if ($options = (array) $this->getValue('options')) {
         foreach ($options as $key => $option) {
             $items[$key] = $option['option'];
         }
     }
     switch ($this->type) {
         case 'text':
             $input = $form->addText($name);
             break;
         case 'textarea':
             $input = $form->addTextArea($name);
             break;
         case 'radio':
             $input = $form->addRadioList($name, NULL, $items);
             break;
         case 'checkbox':
             $input = $form->addCheckboxList($name, NULL, $items);
             break;
         case 'select':
             if ($this->getValue('multiple')) {
                 $input = $form->addMultiSelect($name)->setItems($items, FALSE);
             }
             if (!$this->getValue('multiple')) {
                 $input = $form->addSelect($name)->setItems($items, FALSE);
             }
             break;
         default:
             throw new \Exception();
     }
     if ($this->getValue('isRequired') && isset($input)) {
         $input->setRequired(TRUE);
     }
     return $input;
 }