/** * @param DateTime|string|NULL $value * @return static */ public function setValue($value = NULL) { if ($value instanceof \DateTime) { $value = $value->format($this->format); } return parent::setValue($value); }
/** * Generates control's HTML element. * @return Nette\Utils\Html */ public function getControl() { $input = parent::getControl(); foreach ($this->getRules() as $rule) { if ($rule->isNegative || $rule->branch) { } elseif (in_array($rule->validator, [Form::MIN, Form::MAX, Form::RANGE], TRUE) && in_array($input->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], TRUE)) { if ($rule->validator === Form::MIN) { $range = [$rule->arg, NULL]; } elseif ($rule->validator === Form::MAX) { $range = [NULL, $rule->arg]; } else { $range = $rule->arg; } if (isset($range[0]) && is_scalar($range[0])) { $input->min = isset($input->min) ? max($input->min, $range[0]) : $range[0]; } if (isset($range[1]) && is_scalar($range[1])) { $input->max = isset($input->max) ? min($input->max, $range[1]) : $range[1]; } } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg) && in_array($input->type, ['text', 'search', 'tel', 'url', 'email', 'password'], TRUE)) { $input->pattern = $rule->arg; } } if ($input->type !== 'password' && ($this->rawValue !== '' || $this->emptyValue !== '')) { $input->value = $this->rawValue === '' ? $this->translate($this->emptyValue) : $this->rawValue; } return $input; }
public function validate() { parent::validate(); if ($this->rules->validate() === TRUE) { $this->session->getSection($this->sessionSection)->remove(); } }
/** * Generates control's HTML element. * @return Nette\Utils\Html */ public function getControl() { $value = $this->getValue(); if ($value === '') { $value = $this->translate($this->emptyValue); } return parent::getControl()->setText($value); }
public function getControl() { $control = parent::getControl(); $form = $this->lookup('Nette\\Forms\\Form'); $control->style = "display:none;"; $extIdentifier = substr($this->name, 4); $extName = $form->presenter->mediaManagerService->getLabelExtNameByIdentifier($extIdentifier); $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value; $divContainer = Nette\Utils\Html::el('div'); $divContainer->class('media-container'); $divContent = $divContainer->create('div'); $divContent->class('media-container-content'); $thumbImage = Nette\Utils\Html::el('img'); $buttonParams = array('cid' => $control->id, 'media-extName' => $extName, 'media-trigger' => 'container'); //dump(json_decode($control->value, TRUE)); $encodedParams = json_decode($control->value, TRUE); $mediaType = NULL; $mediaId = NULL; $restoreUrl = NULL; if ($encodedParams !== NULL && is_array($encodedParams)) { $mediaType = isset($encodedParams['mediaType']) ? $encodedParams['mediaType'] : NULL; $mediaId = isset($encodedParams['mediaId']) ? $encodedParams['mediaId'] : NULL; $restoreUrl = isset($encodedParams['restoreUrl']) ? $encodedParams['restoreUrl'] : NULL; } if ($mediaType !== NULL && $mediaId !== NULL) { switch ($mediaType) { case 'file': $file = $form->presenter->mediaManagerService->getFile($mediaId); $section = $form->presenter->mediaManagerService->getFileSection($mediaId); $iconSrc = $form->presenter->mediaManagerService->getFileIconSrc($file); $thumbImage->src = $iconSrc; //$buttonParams = array_merge($buttonParams, $this->_getFileDetailParams($matches[2], $file['folder_id'], $section)); $buttonParams = array_merge($buttonParams, $form->presenter->mediaManagerService->getFileRestoreParams($file['folder_id'], $mediaId, $section, FALSE)); break; case 'gallery': $folder = $form->presenter->mediaManagerService->getFolder($mediaId); $iconSrc = $form->presenter->mediaManagerService->getGalleryIconSrc($folder['folder_id']); $thumbImage->src = $iconSrc; //$buttonParams = array_merge($buttonParams, $this->_getGalleryDetailParams($matches[2], $folder['parent_folder'])); $buttonParams = array_merge($buttonParams, $form->presenter->mediaManagerService->getGalleryRestoreParams($mediaId, $folder['parent_folder'], FALSE)); break; } } $divContent->add($thumbImage); $actionButton = $divContainer->create('a'); $actionButton->href($form->presenter->link('Tiny:pokus', $buttonParams))->class('colorbox vdColorbox')->setText('Otevřít disk'); $sep = $divContainer->create(NULL); $sep->setText(' '); $removeButton = $divContainer->create('a'); $removeButton->href('#')->class('remove-media-item')->cid($control->id)->setText('Smazat'); if (!$control->value) { $removeButton->style('display:none;'); } $divContainer->add($control); return $divContainer; }
/** * Generates control's HTML element. * * @return Nette\Utils\Html */ public function getControl() { $control = parent::getControl(); foreach ($this->getRules() as $rule) { if ($rule->isNegative || $rule->type !== Nette\Forms\Rule::VALIDATOR) { } elseif ($rule->operation === Nette\Forms\Form::RANGE && $control->type !== 'text') { list($control->min, $control->max) = $rule->arg; } elseif ($rule->operation === Nette\Forms\Form::PATTERN) { $control->pattern = $rule->arg; } } if ($control->type !== 'password') { $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value; } return $control; }
/** * Generates control's HTML element. * @return Nette\Utils\Html */ public function getControl() { $input = parent::getControl(); foreach ($this->getRules() as $rule) { if ($rule->isNegative || $rule->branch) { } elseif ($rule->validator === Nette\Forms\Form::RANGE && $input->type !== 'text') { $input->min = isset($rule->arg[0]) && is_scalar($rule->arg[0]) ? $rule->arg[0] : NULL; $input->max = isset($rule->arg[1]) && is_scalar($rule->arg[1]) ? $rule->arg[1] : NULL; } elseif ($rule->validator === Nette\Forms\Form::PATTERN && is_scalar($rule->arg)) { $input->pattern = $rule->arg; } } if ($input->type !== 'password') { $input->value = $this->rawValue === '' ? $this->translate($this->emptyValue) : $this->rawValue; } return $input; }
/** * Generates control's HTML element. * @return Nette\Utils\Html */ public function getControl() { $input = parent::getControl(); foreach ($this->getRules() as $rule) { if ($rule->isNegative || $rule->type !== Nette\Forms\Rule::VALIDATOR) { } elseif ($rule->operation === Nette\Forms\Form::RANGE && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'))) { if (isset($rule->arg[0]) && is_scalar($rule->arg[0])) { $input->min = isset($input->min) ? max($input->min, $rule->arg[0]) : $rule->arg[0]; } if (isset($rule->arg[1]) && is_scalar($rule->arg[1])) { $input->max = isset($input->max) ? min($input->max, $rule->arg[1]) : $rule->arg[1]; } } elseif ($rule->operation === Nette\Forms\Form::PATTERN && is_scalar($rule->arg) && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'))) { $input->pattern = $rule->arg; } } if ($input->type !== 'password') { $input->value = $this->rawValue === '' ? $this->translate($this->emptyValue) : $this->rawValue; } return $input; }
/** * @return Nette\Utils\Html */ public function getStateControlPart() { $countryCode = $this->countryCode ?: $this->defaultCountryCode; $items = $this->getStates($countryCode); $disabled = $this->isDisabled(); // Disabled ? if ($items === NULL && count($items) === 0) { $disabled = TRUE; } if ($items === NULL) { $items = array(NULL => 'without state'); } /** @var Nette\Utils\Html $states */ $states = Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->stateCode)); // Set attributes $states->addAttributes(parent::getControl()->attrs); $states->attrs['id'] = $this->getHtmlId() . '_states'; $states->attrs['name'] = Nette\Forms\Helpers::generateHtmlName($this->lookupPath('Nette\\Forms\\Form') . '_states'); if ($disabled) { $states->attrs['disabled'] = TRUE; } return $states; }
public function addRule($validator, $message = NULL, $arg = NULL) { if ($this->control->type === NULL && in_array($validator, [Form::EMAIL, Form::URL, Form::INTEGER], TRUE)) { static $types = [Form::EMAIL => 'email', Form::URL => 'url', Form::INTEGER => 'number']; $this->control->type = $types[$validator]; } elseif (in_array($validator, [Form::MIN, Form::MAX, Form::RANGE], TRUE) && in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], TRUE)) { if ($validator === Form::MIN) { $range = [$arg, NULL]; } elseif ($validator === Form::MAX) { $range = [NULL, $arg]; } else { $range = $arg; } if (isset($range[0]) && is_scalar($range[0])) { $this->control->min = isset($this->control->min) ? max($this->control->min, $range[0]) : $range[0]; } if (isset($range[1]) && is_scalar($range[1])) { $this->control->max = isset($this->control->max) ? min($this->control->max, $range[1]) : $range[1]; } } elseif ($validator === Form::PATTERN && is_scalar($arg) && in_array($this->control->type, [NULL, 'text', 'search', 'tel', 'url', 'email', 'password'], TRUE)) { $this->control->pattern = $arg; } return parent::addRule($validator, $message, $arg); }
/** * Rangle validator: is a control's value number in specified range? * @param TextBase * @param array min and max value pair * @return bool */ public static function validateRange(TextBase $control, $range) { return Validators::isInRange($control->getValue(), $range); }
/** * Is a control's value float number? * @return bool * @internal */ public static function validateFloat(TextBase $control) { $value = self::filterFloat($control->getValue()); if (Validators::isNumeric($value)) { $control->setValue((double) $value); return TRUE; } return FALSE; }
/** * Float validator: is each value of tag of control value float number? * @param TextBase * @return bool */ public static function validateFloat(TextBase $control) { foreach ($control->getValue() as $tag) { if (!Strings::match($tag, '/^-?[0-9]*[.,]?[0-9]+$/')) { return FALSE; } } return TRUE; }
/** * Rangle validator: is a control's value number in specified range? * @param TextBase * @param array min and max value pair * @return bool */ public static function validateRange(TextBase $control, $range) { return ($range[0] === NULL || $control->getValue() >= $range[0]) && ($range[1] === NULL || $control->getValue() <= $range[1]); }
/** * @dataProvider dp_testToPropertyValue */ public function testToPropertyValue($value, $expected) { $this->control->expects($this->any())->method('getValue')->will($this->returnValue($value)); $result = $this->object->toPropertyValue($this->control, $this->metadata); $this->assertSame($expected, $result); }
public function getControl() { $control = parent::getControl(); $control->setText($this->arrayToText($this->value)); return $control; }
/** * Float validator: is a control's value float number? * @param TextBase * @return bool */ public static function validateFloat(TextBase $control) { return Validators::isNumeric(static::filterFloat($control->getValue())); }
/** * Generates control's HTML element. * @return Nette\Utils\Html */ public function getControl() { return parent::getControl()->setText($this->getRenderedValue()); }
/** * Generates control's HTML element. * @return Nette\Utils\Html */ public function getControl() { $control = parent::getControl(); $control->setText($this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value); return $control; }
/** * 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 \Nette\ComponentModel\IComponent $form form * @return void */ protected function attached($form) { parent::attached($form); if ($form instanceof Form) { $form[$this->getUidFieldName()] = new HiddenField(); } }
public function setValue($value) { return parent::setValue($value instanceof DateTime ? $value->format($this->htmlFormat) : $value); }
/** * @param string|NULL */ public function __construct($caption = NULL) { parent::__construct($caption); $this->setOmitted(); $this->control = Html::el('span')->addClass('static-form-control'); }