Пример #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;
 }
Пример #2
0
 /**
  * Generates control's HTML element.
  * @param  string
  * @return Nette\Web\Html
  */
 public function getControl($caption = NULL)
 {
     $control = parent::getControl();
     $control->value = $this->translate($caption === NULL ? $this->caption : $caption);
     return $control;
 }
Пример #3
0
 /**
  * Generates control's HTML element.
  * @param  mixed
  * @return Nette\Web\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);
         // TODO: separator after last item?
     }
     return $container;
 }
Пример #4
0
	/**
	 * Generates control's HTML element.
	 * @return Nette\Web\Html
	 */
	public function getControl()
	{
		return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)->data('nette-rules', NULL);
	}
Пример #5
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $selected = $this->getValue();
     $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $option = Nette\Web\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 Nette\Web\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;
 }
Пример #6
0
	/**
	 * Generates control's HTML element.
	 * @return Nette\Web\Html
	 */
	public function getControl()
	{
		$control = parent::getControl();
		if ($this->skipFirst) {
			reset($this->items);
			$control->data('nette-empty-value', $this->useKeys ? key($this->items) : current($this->items));
		}
		$selected = $this->getValue();
		$selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
		$option = Nette\Web\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 Nette\Web\Html) {
					$dest->add((string) $value2->selected(isset($selected[$key2])));

				} else {
					$key2 = $this->useKeys ? $key2 : $value2;
					$value2 = $this->translate((string) $value2);
					$dest->add((string) $option->value($key2 === $value2 ? NULL : $key2)->selected(isset($selected[$key2]))->setText($value2));
				}
			}
		}
		return $control;
	}
Пример #7
0
	/**
	 * Generates control's HTML element.
	 * @return Nette\Web\Html
	 */
	public function getControl()
	{
		return parent::getControl()->checked($this->value);
	}
Пример #8
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue);
 }
Пример #9
0
 public function getControl()
 {
     return parent::getControl()->data('nette-empty-value', $this->emptyValue === '' ? NULL : $this->translate($this->emptyValue));
 }