Inheritance: extends Nette\Object
 /**
  * Generates control's HTML element.
  *
  * @return string
  */
 public function getControl()
 {
     $items = $this->getItems();
     reset($items);
     $input = BaseControl::getControl();
     return Helpers::createInputList($this->translate ? $this->translate($items) : $items, array_merge($input->attrs, ['id' => NULL, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'required' => NULL, 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']]]), $this->label->attrs, $this->separator);
 }
Exemple #2
0
	/**
	 * Generates control's HTML element.
	 * @return Html
	 */
	public function getControl($key = NULL)
	{
		if ($key !== NULL) {
			trigger_error(sprintf('Partial %s() is deprecated; use getControlPart() instead.', __METHOD__), E_USER_DEPRECATED);
			return $this->getControlPart($key);
		}

		$input = parent::getControl();
		$ids = array();
		foreach ($this->getItems() as $value => $label) {
			$ids[$value] = $input->id . '-' . $value;
		}

		return $this->container->setHtml(
			Nette\Forms\Helpers::createInputList(
				$this->translate($this->getItems()),
				array_merge($input->attrs, array(
					'id:' => $ids,
					'checked?' => $this->value,
					'disabled:' => $this->disabled,
					'data-nette-rules:' => array(key($ids) => $input->attrs['data-nette-rules']),
				)),
				array('for:' => $ids) + $this->itemLabel->attrs,
				$this->separator
			)
		);
	}
Exemple #3
0
 /**
  * Generates control's HTML element.
  * @return string
  */
 public function getControl()
 {
     $items = $this->getItems();
     reset($items);
     $input = parent::getControl();
     return Nette\Forms\Helpers::createInputList($this->translate($items), array_merge($input->attrs, array('id' => NULL, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'required' => NULL, 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']))), $this->label->attrs, $this->separator);
 }
Exemple #4
0
 /**
  * Generates control's HTML element.
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $items = array();
     foreach ($this->options as $key => $value) {
         $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value);
     }
     return Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(parent::getControl()->attrs)->multiple(TRUE);
 }
 /**
  * Just remove translations from each option
  * @return Nette\Forms\Helpers
  */
 public function getControl()
 {
     $items = $this->prompt === FALSE ? array() : array('' => $this->translate($this->prompt));
     foreach ($this->options as $key => $value) {
         $items[is_array($value) ? $key : $key] = $value;
     }
     return Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(BaseControl::getControl()->attrs);
 }
Exemple #6
0
 /**
  * Generates control's HTML element.
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $items = $this->prompt === FALSE ? [] : ['' => $this->translate($this->prompt)];
     foreach ($this->options as $key => $value) {
         $items[is_array($value) ? $this->translate($key) : $key] = $this->translate($value);
     }
     return Nette\Forms\Helpers::createSelectBox($items, ['selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL])->addAttributes(parent::getControl()->attrs);
 }
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $items = $this->getPrompt() === FALSE ? [] : ['' => $this->translate($this->getPrompt())];
     foreach ($this->options as $key => $value) {
         $items[$this->translate && is_array($value) ? $this->translate($key) : $key] = $this->translate ? $this->translate($value) : $value;
     }
     return Helpers::createSelectBox($items, ['selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL])->addAttributes(BaseControl::getControl()->attrs);
 }
Exemple #8
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     $items = $this->getPrompt() === FALSE ? array() : array('' => $this->translate($this->getPrompt()));
     $translated = array();
     foreach ($this->items as $key => $value) {
         $translated[$key] = $this->translate($value);
     }
     asort($translated);
     return Helpers::createSelectBox($items + $translated, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(parent::getControl()->attrs);
 }
Exemple #9
0
 /**
  * Generates control's HTML element.
  * @return Html
  */
 public function getControl()
 {
     $input = parent::getControl();
     $items = $this->getItems();
     $ids = [];
     if ($this->generateId) {
         foreach ($items as $value => $label) {
             $ids[$value] = $input->id . '-' . $value;
         }
     }
     return $this->container->setHtml(Nette\Forms\Helpers::createInputList($this->translate($items), array_merge($input->attrs, ['id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']]]), ['for:' => $ids] + $this->itemLabel->attrs, $this->separator));
 }
Exemple #10
0
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $name = $this->getHtmlName();
     $day = Html::el('input')->type('number')->title('Den')->placeholder('den')->min(1)->max(31)->name($name . '[day]')->value($this->day);
     $month = Helpers::createSelectBox($this->months, array('selected?' => $this->month === NULL ? '' : $this->month))->name($name . '[month]')->title('Měsíc');
     $year = Html::el('input')->type('number')->min(0)->max(3000)->title('Rok')->placeholder('rok')->name($name . '[year]')->value($this->year);
     if ($this->bootstrap) {
         $day->addClass('form-control');
         $month->addClass('form-control');
         $year->addClass('form-control');
     }
     return Html::el('div')->class('date_input')->setHtml($day . $month . $year);
 }
Exemple #11
0
 /**
  * Generates control's HTML element.
  */
 public function getControl()
 {
     parent::getControl();
     $days = array('' => 'Den') + array_combine(range(1, 31), range(1, 31));
     $yearsRange = range(date('Y'), date('Y') - 110);
     $years = array('' => 'Rok') + array_combine($yearsRange, $yearsRange);
     $monthsCzech = \JiriNapravnik\Common\DateCzech::getCzechMonthsNominativNumericKeys();
     $months = array('' => 'Měsíc');
     for ($i = 1; $i <= 12; $i++) {
         $months[$i] = $monthsCzech[$i];
     }
     $name = $this->getHtmlName();
     return Html::el()->add(Helpers::createSelectBox($days, array('selected?' => $this->day))->name($name . '[day]')->class('form-control day'))->add(Helpers::createSelectBox($months, array('selected?' => $this->month))->name($name . '[month]')->class('form-control month'))->add(Helpers::createSelectBox($years, array('selected?' => $this->year))->name($name . '[year]')->class('form-control year'));
 }
Exemple #12
0
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $name = $this->getHtmlName();
     $day = Html::el('input')->type('number')->title('Den')->placeholder('den')->min(1)->max(31)->name($name . '[day]')->value($this->day);
     $month = Helpers::createSelectBox($this->months, array('selected?' => $this->month === NULL ? '' : $this->month))->name($name . '[month]')->title('Měsíc');
     $year = Html::el('input')->type('number')->min(0)->max(3000)->title('Rok')->placeholder('rok')->name($name . '[year]')->value($this->year);
     $hour = Html::el('input')->type('number')->min(0)->max(23)->title('Hodina')->placeholder('h')->name($name . '[hour]')->value($this->hour);
     $minute = Html::el('input')->type('number')->min(0)->max(59)->title('Minuta')->placeholder('m')->name($name . '[minute]')->value($this->minute);
     if ($this->bootstrap) {
         $day->addClass('form-control');
         $month->addClass('form-control');
         $year->addClass('form-control');
         $hour->addClass('form-control');
         $minute->addClass('form-control');
         return Html::el('div')->class('row date_input')->setHtml(Html::el('div')->class('col-sm-1')->setHtml($day) . Html::el('div')->class('col-sm-2')->setHtml($month) . Html::el('div')->class('col-sm-2')->setHtml($year) . Html::el('div')->class('col-sm-1')->setHtml($hour) . Html::el('div')->class('col-sm-1')->setHtml($minute));
     } else {
         return Html::el('div')->class('date_input')->setHtml($day . $month . $year . $hour . $minute);
     }
 }
 /**
  * @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;
 }
Exemple #14
0
 /**
  * Returns HTML name of control.
  * @return string
  */
 public function getHtmlName()
 {
     return Nette\Forms\Helpers::generateHtmlName($this->lookupPath('Nette\\Forms\\Form'));
 }
Exemple #15
0
 /**
  * @param string $key
  *
  * @return Utils\Html
  *
  * @throws Exceptions\InvalidArgumentException
  */
 public function getControlPart($key)
 {
     $name = $this->getHtmlName();
     // Try to get translator
     $translator = $this->getTranslator();
     if ($translator instanceof Localization\ITranslator && method_exists($translator, 'getLocale') === TRUE) {
         try {
             $locale = $translator->getLocale();
         } catch (\Exception $ex) {
             $locale = 'en_US';
         }
     } else {
         $locale = 'en_US';
     }
     if ($key === static::FIELD_COUNTRY) {
         $control = Forms\Helpers::createSelectBox(array_reduce($this->getAllowedCountries(), function (array $result, $row) use($locale) {
             $countryName = FormPhone\Locale\Locale::getDisplayRegion(FormPhone\Locale\Locale::countryCodeToLocale($row), $locale);
             $result[$row] = Utils\Html::el('option')->setText('+' . $this->phoneUtils->getCountryCodeForCountry($row) . ' (' . $countryName . ')')->addAttributes(['data-mask' => preg_replace('/[0-9]/', '9', $this->phoneUtils->getExampleNationalNumber($row))])->value($row);
             return $result;
         }, []), ['selected?' => $this->country === NULL ? $this->defaultCountry : $this->country]);
         $control->addAttributes(['name' => $name . '[' . static::FIELD_COUNTRY . ']', 'id' => $this->getHtmlId() . '-' . static::FIELD_COUNTRY, 'data-ipub-forms-phone' => '', 'data-settings' => json_encode(['field' => $name . '[' . static::FIELD_NUMBER . ']'])]);
         if ($this->isDisabled()) {
             $control->disabled(TRUE);
         }
         return $control;
     } else {
         if ($key === static::FIELD_NUMBER) {
             $input = parent::getControl();
             $control = Utils\Html::el('input');
             $control->addAttributes(['name' => $name . '[' . static::FIELD_NUMBER . ']', 'id' => $this->getHtmlId() . '-' . static::FIELD_NUMBER, 'value' => $this->number, 'type' => 'text', 'data-nette-empty-value' => Utils\Strings::trim($this->translate($this->emptyValue)), 'data-nette-rules' => $input->{'data-nette-rules'}]);
             if ($this->isDisabled()) {
                 $control->disabled(TRUE);
             }
             return $control;
         }
     }
     throw new Exceptions\InvalidArgumentException('Part ' . $key . ' does not exist.');
 }
Exemple #16
0
 /**
  * Generates control's HTML element.
  * @return Html|string
  */
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $el = clone $this->control;
     return $el->addAttributes(['name' => $this->getHtmlName(), 'id' => $this->getHtmlId(), 'required' => $this->isRequired(), 'disabled' => $this->isDisabled(), 'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules) ?: NULL]);
 }
Exemple #17
0
 /**
  * Returns submitted HTTP data.
  * @return mixed
  */
 public function getHttpData($type = NULL, $htmlName = NULL)
 {
     if ($this->httpData === NULL) {
         if (!$this->isAnchored()) {
             throw new Nette\InvalidStateException('Form is not anchored and therefore can not determine whether it was submitted.');
         }
         $data = $this->receiveHttpData();
         $this->httpData = (array) $data;
         $this->submittedBy = is_array($data);
     }
     if ($htmlName === NULL) {
         return $this->httpData;
     }
     return Helpers::extractHttpData($this->httpData, $htmlName, $type);
 }
Exemple #18
0
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $name = $this->getHtmlName();
     if ($this->options['mode'] === 'full') {
         return Html::el('input', array('type' => 'text', 'name' => $name, 'class' => array(isset($this->options['class']) ? $this->options['class'] : 'selectize' . ' form-control text')))->data('entity', $this->entity)->data('options', $this->options)->value($this->selectizeBack);
     } elseif ($this->options['mode'] === 'select') {
         $this->entity = $this->prompt === FALSE ? $this->entity : self::arrayUnshiftAssoc($this->entity, '', $this->translate($this->prompt));
         return Nette\Forms\Helpers::createSelectBox($this->entity, ['selected?' => $this->selectizeBack])->name($name)->data('entity', $this->entity)->data('options', $this->options)->class(isset($this->options['class']) ? $this->options['class'] : 'selectize' . ' form-control');
     }
 }
 /**
  * @param string
  * @return \Nette\Utils\Html
  * @throws \Nette\InvalidArgumentException
  */
 public function getControlPart($key)
 {
     $name = $this->getHtmlName();
     if ($key === static::NAME_PREFIX) {
         $control = \Nette\Forms\Helpers::createSelectBox(array_combine(static::$phonePrefixes, static::$phonePrefixes), array('selected?' => $this->prefix === NULL ? $this->defaultPrefix : $this->prefix));
         $control->name($name . '[' . static::NAME_PREFIX . ']')->id($this->getHtmlId());
         if ($this->disabled) {
             $control->disabled($this->disabled);
         }
         return $control;
     } elseif ($key === static::NAME_NUMBER) {
         $control = \Nette\Utils\Html::el('input')->name($name . '[' . static::NAME_NUMBER . ']');
         $control->value($this->number);
         $control->type('text');
         if ($this->disabled) {
             $control->disabled($this->disabled);
         }
         return $control;
     }
     throw new \Nette\InvalidArgumentException('Part ' . $key . ' does not exist');
 }
 /**
  * @return Html
  */
 public function getControl()
 {
     $controlName = $this->getHtmlName();
     $date = $this->value ? $this->value : new \DateTime();
     $html = Html::el();
     $input = Html::el('input')->name($controlName . '[js]')->id($this->getHtmlId());
     $input->class[] = 'js';
     $input->class[] = 'date-input';
     $input->data('format', $this->getJsFormat());
     $input->data('settings', $this->settings);
     $input->value($date->format($this->getJsFormat()));
     $html->add($input);
     $container = Html::el('div');
     $container->class[] = 'no-js date-input-container';
     foreach ($this->fields as $name) {
         $rangeValues = $this->range[$name];
         $range = range($rangeValues[0], $rangeValues[1]);
         $fieldName = isset($rangeValues[2]) ? $rangeValues[2] : $name;
         $date = getdate($this->value ? $this->value->getTimestamp() : time());
         $input = Nette\Forms\Helpers::createSelectBox(array_combine($range, $range), array('selected?' => $date[$fieldName]))->name($controlName . '[' . $name . ']');
         $input->class[] = 'no-js';
         $container->add($input . $this->getSeparator($name));
     }
     $html->add($container);
     return $html;
 }
Exemple #21
0
 /**
  * Generates control's HTML element.
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $items = $this->prompt === FALSE ? array() : array('' => $this->translate($this->prompt));
     foreach ($this->items as $key => $value) {
         if (is_array($value)) {
             $key = $this->translate($key);
             foreach ($value as $k => $v) {
                 $items[$key][$k] = $this->translate($v);
             }
         } else {
             $items[$key] = $this->translate($value);
         }
     }
     return Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(parent::getControl()->attrs);
 }
Exemple #22
0
 /**
  * Generates control's HTML element.
  * @param  mixed
  * @return Nette\Utils\Html
  */
 public function getControl($key = NULL)
 {
     $input = parent::getControl();
     if ($key !== NULL) {
         $selected = array_flip((array) $this->value);
         return $input->addAttributes(array('id' => $input->id . '-' . $key, 'checked' => isset($selected[$key]), 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled, 'value' => $key));
     }
     $ids = $items = array();
     foreach ($this->items as $value => $label) {
         $items[$value] = $this->translate($label);
         $ids[$value] = $input->id . '-' . $value;
     }
     return $this->container->setHtml(Nette\Forms\Helpers::createInputList($items, array_merge($input->attrs, array('id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']))), array('for:' => $ids) + $this->label->attrs, $this->separator));
 }
Exemple #23
0
 /**
  * Generates control's HTML element.
  */
 public function getControl()
 {
     $name = $this->getHtmlName();
     return Html::el('input', ['name' => $name . '[day]', 'id' => $this->getHtmlId(), 'value' => $this->day, 'type' => 'number', 'min' => 1, 'max' => 31, 'data-nette-rules' => Helpers::exportRules($this->getRules()) ?: NULL]) . Helpers::createSelectBox([1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], ['selected?' => $this->month])->name($name . '[month]') . Html::el('input', ['name' => $name . '[year]', 'value' => $this->year, 'type' => 'number']);
 }
Exemple #24
0
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $name = $this->getHtmlName();
     $el = clone $this->control;
     if (array_key_exists('ajaxURL', $this->options)) {
         $this->entity = $this->findActiveValue($this->entity, $this->options['valueField'], $this->selectizeBack);
     }
     if ($this->options['mode'] === 'full') {
         return $el->addAttributes(['id' => $this->getHtmlId(), 'type' => 'text', 'name' => $name, 'class' => array(isset($this->options['class']) ? $this->options['class'] : 'selectize' . ' form-control text'), 'data-entity' => $this->entity, 'data-options' => $this->options, 'value' => $this->selectizeBack]);
     } elseif ($this->options['mode'] === 'select') {
         $this->entity = $this->prompt === FALSE ? $this->entity : self::arrayUnshiftAssoc($this->entity, '', $this->translate($this->prompt));
         return Nette\Forms\Helpers::createSelectBox($this->entity, ['selected?' => $this->selectizeBack])->id($this->getHtmlId())->name($name)->data('entity', $this->entity)->data('options', $this->options)->class(isset($this->options['class']) ? $this->options['class'] : 'selectize' . ' form-control')->addAttributes(parent::getControl()->attrs);
     }
 }
Exemple #25
0
 /** @deprecated */
 protected static function exportRules($rules)
 {
     trigger_error(__METHOD__ . '() is deprecated; use Nette\\Forms\\Helpers::exportRules() instead.', E_USER_DEPRECATED);
     return Nette\Forms\Helpers::exportRules($rules);
 }
 /**
  * Loads and process STANDARD http request. NOT uploadify requests!
  */
 public function loadHttpData()
 {
     $name = $this->getHtmlName() . '[token]';
     $data = $this->getForm()->getHttpData();
     // Get queue token for received files
     //  -> js & non-js as well (for js only the token is received)
     if (!empty($data)) {
         $token = Forms\Helpers::extractHttpData($data, $name, Forms\Form::DATA_LINE);
         if ($token) {
             $this->token = $token;
         } else {
             throw new InvalidStateException("Token has not been received! Without token MultipleFileUploader can't identify which files has been received.");
         }
     }
 }