Nette\Forms\Container::addRadioList PHP Метод

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

Adds set of radio button controls to the form.
public addRadioList ( $name, $label = NULL, array $items = NULL ) : RadioList
$items array
Результат Nette\Forms\Controls\RadioList
    public function addRadioList($name, $label = NULL, array $items = NULL)
    {
        return $this[$name] = new Controls\RadioList($label, $items);
    }

Usage Example

Пример #1
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;
 }