예제 #1
0
 public function notifyRule(Rule $rule)
 {
     if (is_string($rule->operation) && strcasecmp($rule->operation, ':float') === 0) {
         $this->addFilter(callback(__CLASS__, 'filterFloat'));
     }
     parent::notifyRule($rule);
 }
예제 #2
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 Form) {
         if ($form->getMethod() !== Form::POST) {
             throw new \InvalidStateException('File upload requires method POST.');
         }
         $form->getElementPrototype()->enctype = 'multipart/form-data';
     }
     parent::attached($form);
 }
예제 #3
0
파일: Button.php 프로젝트: JanTvrdik/nette
 /**
  * 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;
 }
예제 #4
0
 /**
  * Generates label's HTML element.
  * @param  string
  * @return void
  */
 public function getLabel($caption = NULL)
 {
     $label = parent::getLabel($caption);
     $label->for = NULL;
     return $label;
 }
예제 #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()
	{
		return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue)->data('nette-rules', NULL);
	}
예제 #7
0
파일: TextBase.php 프로젝트: redhead/nette
	public function addRule($operation, $message = NULL, $arg = NULL)
	{
		if ($operation === Form::FLOAT) {
			$this->addFilter(callback(__CLASS__, 'filterFloat'));
		}
		return parent::addRule($operation, $message, $arg);
	}
예제 #8
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;
	}
예제 #9
0
	/**
	 * Generates control's HTML element.
	 * @return Nette\Web\Html
	 */
	public function getControl()
	{
		return parent::getControl()->checked($this->value);
	}
예제 #10
0
 /**
  * Generates control's HTML element.
  * @return Nette\Web\Html
  */
 public function getControl()
 {
     return parent::getControl()->value($this->forcedValue === NULL ? $this->value : $this->forcedValue);
 }
예제 #11
0
 public function notifyRule(Rule $rule)
 {
     if (is_string($rule->operation) && !$rule->isNegative) {
         if (strcasecmp($rule->operation, ':float') === 0) {
             $this->addFilter(callback(__CLASS__, 'filterFloat'));
         } elseif (strcasecmp($rule->operation, ':length') === 0) {
             $this->control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg;
         } elseif (strcasecmp($rule->operation, ':maxLength') === 0) {
             $this->control->maxlength = $rule->arg;
         }
     }
     parent::notifyRule($rule);
 }