Author: David Grudl
Inheritance: extends Nette\ComponentModel\Component, implements Nette\Forms\IControl
コード例 #1
0
ファイル: ControlMapper.php プロジェクト: mike227/n-forms
 /**
  * @param object         $object
  * @param string         $fieldName
  * @param BaseControl    $control
  * @param IClassMetadata $classMetadata
  * @throws \NForms\Exceptions\UnexpectedTypeException
  * @return bool
  */
 public function save($object, $fieldName, BaseControl $control, IClassMetadata $classMetadata)
 {
     if ($control->isOmitted() || $control->isDisabled()) {
         return TRUE;
     }
     $value = $control->getValue();
     if ($classMetadata->hasAssociation($fieldName) && $value !== NULL) {
         if ($classMetadata->isSingleValuedAssociation($fieldName)) {
             $value = $this->objectManager->find($classMetadata->getAssociationTargetClass($fieldName), $value);
         } else {
             if (!is_array($value) && (!$value instanceof \ArrayAccess || !$value instanceof \Iterator)) {
                 throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - expected array or ArrayAccess and Iterator instance, given " . get_class($value) . ".");
             }
             $collection = array();
             foreach ($value as $id) {
                 $collection[] = $this->objectManager->find($classMetadata->getAssociationTargetClass($fieldName), $id);
             }
             $value = $collection;
         }
     }
     if ($classMetadata->hasAssociation($fieldName)) {
         $classMetadata->setAssociationValue($object, $fieldName, $value);
     } else {
         if ($control instanceof Nette\Forms\Controls\TextBase && $value === '') {
             $value = NULL;
         }
         $classMetadata->setFieldValue($object, $fieldName, $value);
     }
     return TRUE;
 }
コード例 #2
0
ファイル: NumberMapper.php プロジェクト: voda/formbuilder
 public function toPropertyValue(\Nette\Forms\Controls\BaseControl $control, Builder\Metadata $metadata)
 {
     $value = $control->getValue();
     if ($value !== null) {
         $value = $metadata->type === 'float' ? (double) $value : (int) $value;
     }
     return $value;
 }
コード例 #3
0
 public static function label(Html $label, BaseControl $control, $isPart)
 {
     if ($label->getName() === 'label') {
         $label->addClass('control-label');
     }
     if ($control->isRequired()) {
         $label->addClass('required');
     }
     return $label;
 }
コード例 #4
0
ファイル: ProductForm.php プロジェクト: shophp/shophp
 private function addNominalDiscountControl(BaseControl $priceControl)
 {
     $errorMessage = 'Nominal discount must be between 0 and original price.';
     $control = $this->addText('nominalDiscount', 'Nominal discount');
     $control->setType('number')->setAttribute('step', 'any')->setDefaultValue(0)->addRule(self::FLOAT, $errorMessage)->addRule(function (TextInput $input) use($priceControl) {
         return $input->getValue() >= 0 && $input->getValue() < $priceControl->getValue();
     }, $errorMessage);
     if ($this->editedProduct !== null) {
         $control->setDefaultValue($this->editedProduct->getNominalDiscount());
     }
 }
コード例 #5
0
 /**
  * @param \Nette\Forms\Controls\BaseControl $control
  * @param string|null $errorMessage
  * @param bool|callable $requiring
  */
 private function resolveRequiring(\Nette\Forms\Controls\BaseControl $control, $errorMessage = null, $requiring = false)
 {
     if ($requiring === true) {
         $control->setRequired($errorMessage !== null ? $errorMessage : true);
     } elseif (is_callable($requiring)) {
         $condition = $requiring($control);
         if (!$condition instanceof \Nette\Forms\Rules) {
             throw new RequiredFormFieldResolutionException('Requiring call must return instance of \\Nette\\Forms\\Rules.');
         }
         $condition->setRequired($errorMessage !== null ? $errorMessage : true);
     }
 }
コード例 #6
0
ファイル: DependencyHelper.php プロジェクト: mike227/n-forms
 public function createButton()
 {
     if ($this->button) {
         return FALSE;
     }
     /** @var Nette\Forms\Container $container */
     $container = $this->control->lookup('Nette\\Forms\\Container');
     $name = $this->control->getName() . self::$buttonSuffix;
     $this->button = new SubmitButton("Apply");
     $this->button->setValidationScope(false);
     $container->addComponent($this->button, $name);
     $this->control->getControlPrototype()->addAttributes(array('data-apply-button' => $this->button->getHtmlId()));
     return TRUE;
 }
コード例 #7
0
ファイル: ReCaptcha.php プロジェクト: bazo/translation-ui
 public function __construct($caption, $publicKey, $privateKey)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct($caption);
     $this->publicKey = $publicKey;
     $this->privateKey = $privateKey;
 }
コード例 #8
0
ファイル: PatternInput.php プロジェクト: dansilovsky/calendar
 /**
  * @return ShiftPatternDate
  */
 public function __construct(Template $template, DateTime $date, $templateFileName)
 {
     parent::__construct(null);
     $this->addRule(__CLASS__ . '::validatePattern', 'Shift pattern is invalid.');
     $this->_template = $template;
     $this->_template->setFile(__DIR__ . "/{$templateFileName}");
     $this->_template->registerHelper('dayName', function ($dayNumber) {
         return DateTime::dayName($dayNumber);
     });
     $this->_template->registerHelper('padTime', function ($t) {
         if ($t < 10) {
             return '0' . $t;
         }
         return $t;
     });
     $this->_template->registerHelper('selectOption', function ($timeUnit, $time, $type) {
         $timeUnit = (int) $timeUnit;
         list($hour, $minute) = explode(':', $time);
         $hour = (int) $hour;
         $minute = (int) $minute;
         if ($type === 'h') {
             return $timeUnit === $hour ? 'selected="selected"' : '';
         }
         if ($type === 'm') {
             return $timeUnit === $minute ? 'selected="selected"' : '';
         }
     });
     // returns curren formated date and moves date one day forward
     $this->_template->registerHelper('day', function ($date) {
         $day = $date->format('j F');
         $date->addDay();
         return $day;
     });
     $this->_date = $date;
 }
コード例 #9
0
 public function __construct($caption = NULL, $side, $border)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct($caption);
     $this->side = $side;
     $this->border = $border;
 }
コード例 #10
0
 public function __construct($caption = NULL, $min, $max)
 {
     $this->monitor('Nette\\Forms\\Form');
     parent::__construct($caption);
     $this->min = $min;
     $this->max = $max;
 }
コード例 #11
0
ファイル: Selectize.php プロジェクト: nechutny/form-selectize
 public function __construct($label = null, array $entity = NULL, array $config = NULL)
 {
     parent::__construct($label);
     $this->entity = $entity;
     $this->labelName = $label;
     $this->options = $config;
 }
コード例 #12
0
 /**
  * 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);
 }
コード例 #13
0
 /**
  * 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);
 }
コード例 #14
0
 /**
  * @param  ReCaptcha $reCaptcha
  * @param  Http\Request $httpRequest
  * @param  string $caption
  */
 public function __construct(ReCaptcha $reCaptcha, Http\Request $httpRequest, $caption = NULL)
 {
     parent::__construct($caption);
     $this->setOmitted();
     $this->reCaptcha = $reCaptcha;
     $this->httpRequest = $httpRequest;
     $this->control = $reCaptcha->getHtml();
 }
コード例 #15
0
 /**
  * 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);
 }
コード例 #16
0
ファイル: Markup.php プロジェクト: minetro/forms
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $parentControl = parent::getControl();
     $control = $this->getWrapperPrototype();
     $control->addAttributes(['id' => $parentControl->id]);
     $control->setHtml($this->getContent());
     return $control;
 }
コード例 #17
0
ファイル: MarkupControl.php プロジェクト: f3l1x/nette-plugins
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $parentControl = parent::getControl();
     $control = $this->getWrapperPrototype();
     $control->setId($parentControl->getId());
     $control->setHtml($this->getContent());
     return $control;
 }
コード例 #18
0
 /**
  * Update html class of control
  */
 protected function updateControlClass()
 {
     if ($this->controlClass !== null) {
         $classes = explode(" ", $this->control->getControlPrototype()->class);
         if (!in_array($this->controlClass, $classes)) {
             $this->control->getControlPrototype()->class($this->controlClass);
         }
     }
 }
コード例 #19
0
ファイル: TextOutput.php プロジェクト: pipaslot/forms
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $container = clone $this->container;
     parent::getControl();
     $control = Html::el("div", array("style" => "text-align:justify"));
     $control->setHtml($this->translate((string) $this->getValue()));
     $container->add($control);
     return $container;
 }
コード例 #20
0
ファイル: NetteGMapPicker.php プロジェクト: venca-x/nettegmap
 public function getTextboxControl($name)
 {
     $control = clone parent::getControl();
     $control->type = "text";
     $control->id = $name;
     $control->name .= "[{$name}]";
     $control->value = $this->value[$name];
     return $control;
 }
コード例 #21
0
ファイル: HiddenField.php プロジェクト: jjanekk/forms
 public function __construct($persistentValue = NULL)
 {
     parent::__construct();
     $this->control->type = 'hidden';
     if ($persistentValue !== NULL) {
         $this->unmonitor(Nette\Forms\Form::class);
         $this->persistValue = TRUE;
         $this->value = (string) $persistentValue;
     }
 }
コード例 #22
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  Nette\Forms\IComponent
  * @return void
  */
 protected function attached($form)
 {
     if ($form instanceof Nette\Forms\Form) {
         if ($form->getMethod() !== Nette\Forms\Form::POST) {
             throw new Nette\InvalidStateException('File upload requires method POST.');
         }
         $form->getElementPrototype()->enctype = 'multipart/form-data';
     }
     parent::attached($form);
 }
コード例 #23
0
 /**
  * @param string $siteKey
  * @param string $theme
  * @param string|NULL $caption
  */
 public function __construct($siteKey, $theme, $type, $size, $caption = NULL)
 {
     parent::__construct($caption);
     $this->siteKey = $siteKey;
     $this->theme = $theme;
     $this->type = $type;
     $this->size = $size;
     $this->control = Html::el('div')->addAttributes(['class' => 'g-recaptcha', 'data-sitekey' => $this->siteKey, 'data-theme' => $this->theme, 'data-type' => $this->type, 'data-size' => $this->size]);
     $this->setOmitted();
 }
コード例 #24
0
ファイル: Checkbox3S.php プロジェクト: lohini/framework
 /**
  * Generates control's HTML element
  *
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->addClass('checkbox3s');
     $val = $this->getValue();
     $control->data('lohini-state', $val ?: 0);
     if ($val == 1) {
         $control->checked = 'checked';
     }
     return Html::el('span')->add($control)->addClass('cb3s');
 }
コード例 #25
0
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $input = BaseControl::getControl();
     $items = $this->getItems();
     $ids = [];
     if ($this->generateId) {
         foreach ($items as $value => $label) {
             $ids[$value] = $input->id . '-' . $value;
         }
     }
     return $this->container->setHtml(Helpers::createInputList($this->translate ? $this->translate($items) : $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));
 }
コード例 #26
0
ファイル: TimePicker.php プロジェクト: soundake/pd
 /**
  * Generates control's HTML element.
  *
  * @author   Jan Tvrdík
  * @return   Nette\Web\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->addClass($this->className);
     //		list($min, $max) = $this->extractRangeRule($this->getRules());
     //		if ($min !== NULL) $control->min = $min->format(self::W3C_DATE_FORMAT);
     //		if ($max !== NULL) $control->max = $max->format(self::W3C_DATE_FORMAT);
     if ($this->value) {
         $control->value = $this->value->format(self::W3C_DATE_FORMAT);
     }
     return $control;
 }
コード例 #27
0
 static function register()
 {
     BaseControl::extensionMethod('addDataFlag', function (BaseControl $that, $name) {
         $that->getControlPrototype()->addAttributes(['data-' . $name => TRUE]);
         return $that;
     });
     BaseControl::extensionMethod('hasDataFlag', function (BaseControl $that, $name) {
         return isset($that->getControlPrototype()->attrs['data-' . $name]);
     });
     BaseControl::extensionMethod('removeDataFlag', function (BaseControl $that, $name) {
         unset($that->getControlPrototype()->attrs['data-' . $name]);
         return $that;
     });
 }
コード例 #28
0
ファイル: Static.php プロジェクト: zaxcms/framework
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $value = $this->value;
     foreach ($this->filters as $filter) {
         $value = $filter($value);
     }
     $p = parent::getControl()->id($this->getHtmlId())->addClass('form-control-static');
     if ($value instanceof Html) {
         return $p->setHtml($value->addClass('control-label'));
     } else {
         return $p->setText(Html::el('span')->addClass('control-label')->setText((string) $value));
     }
 }
コード例 #29
0
ファイル: DateInput.php プロジェクト: jirinapravnik/common
 /**
  * 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'));
 }
コード例 #30
0
ファイル: DatePicker.php プロジェクト: hleumas/databaza
 /**
  * Generates control's HTML element.
  *
  * @author   Jan Tvrdík
  * @return   Nette\Utils\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->addClass($this->className);
     list($min, $max) = $this->extractRangeRule($this->getRules());
     if ($min !== NULL) {
         $control->data['min'] = $min->format($this->format);
     }
     if ($max !== NULL) {
         $control->data['max'] = $max->format($this->format);
     }
     if ($this->value) {
         $control->value = $this->value->format($this->format);
     }
     return $control;
 }