Пример #1
0
	/**
	 * This method will be called when the component (or component's parent)
	 * becomes attached to a monitored object. Do not call this method yourself.
	 * @param  IComponent
	 * @return void
	 */
	protected function attached($form)
	{
		if ($form instanceof NForm) {
			if ($form->getMethod() !== NForm::POST) {
				throw new InvalidStateException('File upload requires method POST.');
			}
			$form->getElementPrototype()->enctype = 'multipart/form-data';
		}
		parent::attached($form);
	}
Пример #2
0
	/**
	 * Generates control's HTML element.
	 * @param  string
	 * @return NHtml
	 */
	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.
	 * @return NHtml
	 */
	public function getControl()
	{
		$selected = $this->getValue();
		$selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
		$control = parent::getControl();
		$option = NHtml::el('option');

		if ($this->prompt !== FALSE) {
			$control->add($this->prompt instanceof NHtml
				? $this->prompt->value('')
				: (string) $option->value('')->setText($this->translate((string) $this->prompt))
			);
		}

		foreach ($this->items as $key => $value) {
			if (!is_array($value)) {
				$value = array($key => $value);
				$dest = $control;
			} else {
				$dest = $control->create('optgroup')->label($this->translate($key));
			}

			foreach ($value as $key2 => $value2) {
				if ($value2 instanceof NHtml) {
					$dest->add((string) $value2->value($key2)
						->selected(isset($selected[$key2])));

				} else {
					$key2 = $this->useKeys ? $key2 : $value2;
					$dest->add((string) $option->value($key2)
						->selected(isset($selected[$key2]))
						->setText($this->translate((string) $value2)));
				}
			}
		}
		return $control;
	}
Пример #4
0
 function addRule($operation, $message = NULL, $arg = NULL)
 {
     if ($operation === NForm::FLOAT) {
         $this->addFilter(callback(__CLASS__, 'filterFloat'));
     }
     return parent::addRule($operation, $message, $arg);
 }
Пример #5
0
 /**
  * Generates label's HTML element.
  * @param caption
  * @return Nette\Web\Html
  */
 public function getLabel($caption = NULL)
 {
     $label = parent::getLabel($caption);
     $label->for = NULL;
     return $label;
 }
Пример #6
0
	/**
	 * Generates control's HTML element.
	 * @return NHtml
	 */
	public function getControl()
	{
		return parent::getControl()
			->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)
			->data('nette-rules', NULL);
	}
Пример #7
0
	/**
	 * Generates control's HTML element.
	 * @return NHtml
	 */
	public function getControl()
	{
		return parent::getControl()->checked($this->value);
	}
Пример #8
0
	public function addRule($operation, $message = NULL, $arg = NULL)
	{
		if ($operation === NForm::FLOAT) {
			$this->addFilter(array(__CLASS__, 'filterFloat'));

		} elseif ($operation === NForm::LENGTH || $operation === NForm::MAX_LENGTH) {
			$tmp = is_array($arg) ? $arg[1] : $arg;
			$this->control->maxlength = is_scalar($tmp) ? $tmp : NULL;
		}
		return parent::addRule($operation, $message, $arg);
	}
Пример #9
0
	/**
	 * Generates control's HTML element.
	 * @return NHtml
	 */
	public function getControl()
	{
		$control = parent::getControl();
		if ($this->prompt) {
			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 = NHtml::el('option');

		foreach ($this->items as $key => $value) {
			if (!is_array($value)) {
				$value = array($key => $value);
				$dest = $control;

			} else {
				$dest = $control->create('optgroup')->label($this->translate($key));
			}

			foreach ($value as $key2 => $value2) {
				if ($value2 instanceof NHtml) {
					$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;
	}
Пример #10
0
Файл: loader.php Проект: GE3/GE3
 function notifyRule(NRule $rule)
 {
     if (is_string($rule->operation) && strcasecmp($rule->operation, ':float') === 0) {
         $this->addFilter(callback(__CLASS__, 'filterFloat'));
     }
     parent::notifyRule($rule);
 }