/**
* @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;
}