Inheritance: extends BaseControl
Esempio n. 1
0
 /**
  * Performs the server side validation.
  * @return void
  */
 public function validate()
 {
     parent::validate();
     if (!$this->isDisabled() && $this->prompt === FALSE && $this->getValue() === NULL && $this->options) {
         $this->addError(Nette\Forms\Validator::$messages[self::VALID]);
     }
 }
Esempio n. 2
0
 /**
  * Generates control's HTML element.
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $items = $this->prompt === FALSE ? [] : ['' => $this->translate($this->prompt)];
     foreach ($this->options as $key => $value) {
         $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value);
     }
     return Nette\Forms\Helpers::createSelectBox($items, ['selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL] + $this->optionAttributes)->addAttributes(parent::getControl()->attrs);
 }
 /**
  * Just remove translations from each option
  * @return Nette\Forms\Helpers
  */
 public function getControl()
 {
     $input = ChoiceControl::getControl();
     $items = $this->getItems();
     $ids = array();
     if ($this->generateId) {
         foreach ($items as $value => $label) {
             $ids[$value] = $input->id . '-' . $value;
         }
     }
     return $this->container->setHtml(Nette\Forms\Helpers::createInputList($items, array_merge($input->attrs, array('id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']))), array('for:' => $ids) + $this->itemLabel->attrs, $this->separator));
 }
Esempio n. 4
0
 /**
  * Sets options and option groups from which to choose.
  *
  * @return self
  */
 public function setItems(array $items, $useKeys = TRUE)
 {
     if (!$useKeys) {
         $res = array();
         foreach ($items as $key => $value) {
             unset($items[$key]);
             if (is_array($value)) {
                 foreach ($value as $val) {
                     $res[$key][(string) $val] = $val;
                 }
             } else {
                 $res[(string) $value] = $value;
             }
         }
         $items = $res;
     }
     $this->options = $items;
     return ChoiceControl::setItems(Arrays::flatten($items, TRUE));
 }
Esempio n. 5
0
 /**
  * Performs the server side validation.
  * @return void
  */
 public function validate()
 {
     parent::validate();
     if (!$this->isDisabled() && $this->prompt === FALSE && $this->getValue() === NULL) {
         $this->addError(Nette\Forms\Rules::$defaultMessages[self::VALID]);
     }
 }
Esempio n. 6
0
 /**
  * @return Html
  */
 public function getLabelPart($key = NULL)
 {
     return func_num_args() ? parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key) : $this->getLabel();
 }
Esempio n. 7
0
 /**
  * @return Nette\Utils\Html
  */
 public function getLabelPart($key)
 {
     return parent::getLabel($this->items[$key])->for($this->getHtmlId() . '-' . $key);
 }