Exemplo n.º 1
0
 public function getControl()
 {
     $control = parent::getControl();
     foreach ($this->getRules() as $rule) {
         if ($rule->type === Rule::VALIDATOR && !$rule->isNegative && ($rule->operation === Form::LENGTH || $rule->operation === Form::MAX_LENGTH)) {
             $control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg;
         }
     }
     if ($this->emptyValue !== '') {
         $control->data('nette-empty-value', $this->translate($this->emptyValue));
     }
     return $control;
 }
Exemplo n.º 2
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     $control = FormControl::getControl();
     // skopirovany kod z SelectBox.php
     if ($this->isFirstSkipped()) {
         $items = $this->items;
         reset($items);
         $control->data['nette-empty-value'] = $this->areKeysUsed() ? key($items) : current($items);
     }
     $selected = $this->getValue();
     $this->selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $this->formatOptions($this->items, $control);
     return $control;
 }
Exemplo n.º 3
0
 /**
  * Generates control's HTML element.
  * @param  mixed
  * @return Html
  */
 public function getControl($key = NULL)
 {
     if ($key === NULL) {
         $container = clone $this->container;
         $separator = (string) $this->separator;
     } elseif (!isset($this->items[$key])) {
         return NULL;
     }
     $control = parent::getControl();
     $id = $control->id;
     $counter = -1;
     $value = $this->value === NULL ? NULL : (string) $this->getValue();
     $label = Html::el('label');
     foreach ($this->items as $k => $val) {
         $counter++;
         if ($key !== NULL && $key != $k) {
             continue;
         }
         // intentionally ==
         $control->id = $label->for = $id . '-' . $counter;
         $control->checked = (string) $k === $value;
         $control->value = $k;
         if ($val instanceof Html) {
             $label->setHtml($val);
         } else {
             $label->setText($this->translate($val));
         }
         if ($key !== NULL) {
             return (string) $control . (string) $label;
         }
         $container->add((string) $control . (string) $label . $separator);
         unset($control->data['nette-rules']);
         // TODO: separator after last item?
     }
     return $container;
 }
Exemplo n.º 4
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->value = $this->translate($this->caption);
     return $control;
 }
Exemplo n.º 5
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     return parent::getControl()->checked($this->value);
 }
Exemplo n.º 6
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue);
 }
Exemplo n.º 7
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     $container = clone $this->container;
     $separator = (string) $this->separator;
     $control = parent::getControl();
     $id = $control->id;
     $counter = 0;
     $value = $this->value === NULL ? NULL : (string) $this->getValue();
     $label = Html::el('label');
     foreach ($this->items as $key => $val) {
         $control->id = $label->for = $id . '-' . $counter;
         $control->checked = (string) $key === $value;
         $control->value = $key;
         if ($val instanceof Html) {
             $label->setHtml($val);
         } else {
             $label->setText($this->translate($val));
         }
         $container->add((string) $control . (string) $label . $separator);
         $counter++;
         // TODO: separator after last item?
     }
     return $container;
 }
Exemplo n.º 8
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $selected = $this->getValue();
     $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $option = Html::el('option');
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             $value = array($key => $value);
             $dest = $control;
         } else {
             $dest = $control->create('optgroup')->label($key);
         }
         foreach ($value as $key2 => $value2) {
             if ($value2 instanceof Html) {
                 $dest->add((string) $value2->selected(isset($selected[$key2])));
             } elseif ($this->useKeys) {
                 $dest->add((string) $option->value($key2)->selected(isset($selected[$key2]))->setText($this->translate($value2)));
             } else {
                 $dest->add((string) $option->selected(isset($selected[$value2]))->setText($this->translate($value2)));
             }
         }
     }
     return $control;
 }
Exemplo n.º 9
0
 public function getControl()
 {
     return parent::getControl()->data('nette-empty-value', $this->emptyValue === '' ? NULL : $this->translate($this->emptyValue));
 }
Exemplo n.º 10
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)->data('nette-rules', NULL);
 }