Author: David Grudl
Inheritance: extends TextBase
Exemple #1
0
 /**
  *
  * @param string $name
  * @param string $label
  * @return Html5Input
  */
 public function addEmail($name, $label = NULL)
 {
     $input = new \Nette\Forms\Controls\TextInput($label);
     $input->type = 'email';
     $input->addCondition(Form::FILLED)->addRule(Form::EMAIL, '%label must be a valid email');
     return $this[$name] = $input;
 }
Exemple #2
0
 public function valideFormNewSystemName(\Nette\Forms\Controls\TextInput $input)
 {
     $privilege = $this->privileges->where('system_name', $input->getValue());
     if (!$privilege->fetch()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Create control from configuration or return NULL if factory does not match config.
  *
  * @param IControlConfig $config
  * @return NULL|BaseControl
  */
 public function createControl(IControlConfig $config)
 {
     switch ($config->getType()) {
         case IControlConfig::BUTTON:
             return new Controls\Button($config->getLabel());
         case IControlConfig::CHECKBOX:
             return new Controls\Checkbox($config->getLabel());
         case IControlConfig::EMAIL:
             $input = new Controls\TextInput($config->getLabel());
             $input->setType('email');
             return $input;
         case IControlConfig::HIDDEN:
             return new Controls\HiddenField();
         case IControlConfig::PASSWORD:
             $input = new Controls\TextInput($config->getLabel());
             $input->setType('password');
             return $input;
         case IControlConfig::SUBMIT:
             return new Controls\SubmitButton($config->getLabel());
         case IControlConfig::TEXT:
             return new Controls\TextInput($config->getLabel());
         case IControlConfig::TEXTAREA:
             return new Controls\TextArea($config->getLabel());
         case IControlConfig::DATE_TIME:
             $input = new Controls\TextInput($config->getLabel());
             return $input;
         case IControlConfig::DATE:
             $input = new Controls\TextInput($config->getLabel());
             return $input;
         case IControlConfig::TIME:
             $input = new Controls\TextInput($config->getLabel());
             return $input;
         case IControlConfig::URL:
             $input = new Controls\TextInput($config->getLabel());
             $input->setType('url');
             return $input;
         case IControlConfig::INTEGER:
             $input = new Controls\TextInput($config->getLabel());
             $input->setType('number');
             return $input;
         case IControlConfig::FLOAT:
             $input = new Controls\TextInput($config->getLabel());
             $input->setType('number');
             $input->setAttribute('step', 'any');
             return $input;
     }
     return new Nette\Forms\Controls\TextInput($config->getLabel());
 }
 public function getControl()
 {
     $control = parent::getControl();
     $control->class = 'text datepicker';
     $control->autocomplete = 'off';
     return $control;
 }
Exemple #5
0
 /**
  * Generates control's HTML element.
  *
  * @return \Nette\Utils\Html
  */
 public function getControl()
 {
     $container = clone $this->container;
     $container->add(' <div class="input-group">' . parent::getControl());
     $dest = '';
     $s = null;
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             $value = array($key => $value);
         }
         foreach ($value as $key2 => $value2) {
             if ($value2 instanceof \Nette\Utils\Html) {
                 $dest .= '<li><a href="#">' . $value2 . '</a></li>';
             } else {
                 $key2 = $this->useKeys ? $key2 : $value2;
                 $value2 = $this->translate((string) $value2);
                 if ($key2 == $this->value) {
                     $s = $value2;
                 }
                 $dest .= '<li><a href="#">' . $value2 . '</a></li>';
             }
         }
     }
     $container->add('<div class="input-group-btn">
     <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="textWithSelect-text">' . $s . '</span> <span class="caret"></span></button>
     <ul class="dropdown-menu pull-right">');
     $container->add($dest);
     $container->add('</div></div>');
     return $container;
 }
 /**
  * @dataProvider dp_testToPropertyValueWithFloats
  */
 public function testToPropertyValueWithFloats($value, $expected)
 {
     $this->metadata->type = 'float';
     $this->control->expects($this->any())->method('getValue')->will($this->returnValue($value));
     $result = $this->object->toPropertyValue($this->control, $this->metadata);
     $this->assertSame($expected, $result);
 }
Exemple #7
0
 /**
  * Sets control's value.
  *
  * @param $value
  * @return MoneyControl
  * @override
  */
 public function setValue($value)
 {
     foreach ($this->filtersIn as $filter) {
         $value = $filter($value);
     }
     return parent::setValue($value);
 }
Exemple #8
0
 /**
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->value = implode(",", (array) $this->getValue());
     $control->addAttributes(array("data-role" => "tagsinput"));
     return $control;
 }
Exemple #9
0
 /**
  * Generates control's HTML element
  *
  * @return \Nette\Utils\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->class = 'datetimepicker form-control';
     $control->readonly = TRUE;
     return $control;
 }
Exemple #10
0
 /**
  * @inheritdoc
  * @return Html
  */
 public function getControl()
 {
     $control = clone $this->fullControl;
     $control->insert(0, parent::getControl());
     // the original text input control is injected only there
     return $control;
 }
Exemple #11
0
 /**
  * Sets date
  *
  * @param string $value date
  * @return void
  */
 public function setValue($value)
 {
     if ($value instanceof \DateTime) {
         $value = $value->format($this->format);
     }
     parent::setValue($value);
 }
Exemple #12
0
 /**
  * Generates control's HTML element
  *
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl()->addClass('pswdinput');
     $this->data['fid'] = $this->getForm()->getElementPrototype()->id;
     $control->data('lohini-pswd', \Nette\Utils\Json::encode(array_filter($this->data)));
     return Html::el('span', ['style' => 'position: relative; float: left;'])->add($control);
 }
Exemple #13
0
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     $this->operation = $operation;
     if ($operation === Form::FLOAT) {
         $this->addFilter(callback(__CLASS__, 'filterFloat'));
     }
     return parent::addRule($operation, $message, $arg);
 }
 /**
  * Sets control's value.
  * @param  string
  * @return self
  */
 public function setValue($value = null)
 {
     if ($value instanceof \DateTime) {
         $value = $value->format("d.m.Y");
     }
     parent::setValue($value);
     return $this;
 }
Exemple #15
0
 protected function attached($component)
 {
     parent::attached($component);
     $this->componentControlAttached($component);
     if ($component instanceof Nette\Application\IPresenter) {
         $this->control->{'data-typeahead-url'} = $this->link('autocomplete!', ['q' => '__QUERY_PLACEHOLDER__']);
     }
 }
Exemple #16
0
 /**
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->appendAttribute('class', ['js', 'date-input']);
     $control->data('format', $this->format);
     $control->data('settings', $this->settings);
     if ($this->value) {
         $control->value($this->value->format($this->format));
     }
     return $control;
 }
Exemple #17
0
	/**
	 * @param \DateTime
	 * @return BaseDateTime
	 */
	public function setValue($value = NULL)
	{
		try {
			if ($value instanceof \DateTime) {
				return parent::setValue($value->format(static::$format));
			} else {
				return parent::setValue($value);
			}
		} catch (\Exception $e) {
			return parent::setValue(NULL);
		}
	}
 /**
  * @param \DateTime
  * @return BaseDateTime
  */
 public function setValue($value)
 {
     try {
         if ($value instanceof DateTime || $value instanceof \DibiDateTime) {
             parent::setValue($value->format($this->format));
         } elseif ($value != '') {
             $date = DateTime::from($value);
             parent::setValue($date->format($this->format));
         }
     } catch (\Exception $e) {
         return parent::setValue(NULL);
     }
 }
Exemple #19
0
 public function getValue()
 {
     $value = parent::getValue();
     if ($this->multiple) {
         $images = array();
         foreach (explode(',', $value) as $img) {
             if ($img != '') {
                 $images[] = $img;
             }
         }
         return $images;
     } else {
         return $value;
     }
 }
 /**
  * @return Nette\Utils\Html
  */
 public function getControl($needLink = TRUE)
 {
     $control = parent::getControl();
     if (!$this->link) {
         $presenter = $this->lookup('Nette\\Application\\IPresenter', FALSE);
         if ($presenter || $needLink) {
             $url = $this->lookup('Nette\\Application\\IPresenter')->link('suggestion', array('path' => base64_encode($this->lookupPath('Nette\\Application\\IPresenter'))));
             $control->data('url', urldecode($url));
         }
     } else {
         $url = $this->link;
         $control->data('url', urldecode($url));
     }
     $control->appendAttribute('class', 'suggestion-input');
     $control->data('suggestion', $this->settings);
     return $control;
 }
Exemple #21
0
 public function getControl()
 {
     $container = Nette\Utils\Html::el('span');
     $control = parent::getControl();
     $control->class[] = 'form-control integerPicker';
     /*$template = $this->getForm()->getPresenter()->createTemplate();
     		$template->setFile(__DIR__.'/Templates/control.latte');
     		$template->input = $control; */
     $context = $this->getForm()->getPresenter()->getContext();
     $template = new Nette\Templating\FileTemplate(__DIR__ . '/Templates/control.latte');
     $latte = $context->getService('nette.latte');
     $template->registerFilter($latte);
     vBuilder\Latte\Macros\SystemMacros::install($latte->compiler);
     $template->context = $context;
     $template->input = $control;
     $template->_control = $this->getForm()->lookup('Nette\\Application\\UI\\Control', true);
     $container->setHtml($template);
     return $container;
 }
Exemple #22
0
 /**
  * Adds single-line text input control used for sensitive input such as passwords.
  * @param  string  control name
  * @param  string  label
  * @param  int  width of the control (deprecated)
  * @param  int  maximum number of characters the user may enter
  * @return Nette\Forms\Controls\TextInput
  */
 public function addPassword($name, $label = NULL, $cols = NULL, $maxLength = NULL)
 {
     $control = new Controls\TextInput($label, $maxLength);
     if ($cols) {
         trigger_error(__METHOD__ . '() third parameter $cols is deprecated, use setAttribute("size", ...).', E_USER_DEPRECATED);
         $control->setAttribute('size', $cols);
     }
     return $this[$name] = $control->setType('password');
 }
 /**
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $this->createRule();
     if ($this->settings) {
         $control->data('mask-input', $this->settings);
     }
     return $control;
 }
 /**
  * @return TextInput
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control = $this->addAntispamScript($control);
     return $control;
 }
Exemple #25
0
 /**
  * Returns the control's HTML
  *
  * Adds the javascript code for initializing the functionality
  * 
  * @return Html
  * @throws InvalidStateException If no suggest link is provided
  */
 public function getControl()
 {
     $control = parent::getControl();
     if ($this->suggestLink === NULL) {
         throw new InvalidStateException('SuggustInput::$suggestLink cannot be NULL');
     }
     $control->data('nette-suggestLink', $this->suggestLink);
     $options = $this->getJsOptions();
     if (!isset($options['lang'])) {
         $options['lang'] = self::$defaultUiLanguage;
     }
     $options = substr(PHP_VERSION_ID >= 50400 ? json_encode($options, JSON_UNESCAPED_UNICODE) : json_encode($options), 1, -1);
     $options = preg_replace('#"([a-z0-9_]+)":#i', '$1:', $options);
     $options = preg_replace('#(?<!\\\\)"(?!:[^a-z])([^\\\\\',]*)"#i', "'\$1'", $options);
     $control->data('nette-suggestInput-options', '{' . $options . '}');
     $control->class[] = 'suggestInput';
     return $control;
 }
 public function getControl()
 {
     $control = parent::getControl();
     $control->value = $this->value;
     return $control;
 }
Exemple #27
0
 /**
  * Generates control's HTML element
  *
  * @return \Nette\Utils\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->readonly = TRUE;
     return $control;
 }
Exemple #28
0
 /**
  * Adds a validation rule.
  * @param  mixed      rule type
  * @param  string     message to display for invalid data
  * @param  mixed      optional rule arguments
  * @return FormControl  provides a fluent interface
  */
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     switch ($operation) {
         case Form::EQUAL:
             if (!is_array($arg)) {
                 throw new \Nette\InvalidArgumentException(__METHOD__ . '(' . $operation . ') must be compared to array.');
             }
     }
     return parent::addRule($operation, $message, $arg);
 }
 /**
  * Adds single-line text input control used for sensitive input such as passwords.
  * @param  string  control name
  * @param  string  label
  * @param  int  width of the control (deprecated)
  * @param  int  maximum number of characters the user may enter
  * @return Nette\Forms\Controls\TextInput
  */
 public function addPassword($name, $label = NULL, $cols = NULL, $maxLength = NULL)
 {
     $control = new Controls\TextInput($label, $maxLength);
     $control->setAttribute('size', $cols);
     return $this[$name] = $control->setType('password');
 }
 /**
  * @inheritdoc
  */
 public function setDefaultValue($value)
 {
     if (!$value instanceof \DateTime) {
         $type = gettype($value);
         throw new InvalidArgumentException(sprintf("As default value, %s object must be given, '%s' given instead.", \DateTime::class, $type === 'object' ? get_class($value) : $type));
     }
     return parent::setDefaultValue($value);
 }