Esempio n. 1
0
 /**
  * Generate the upload field.
  *
  * @param ContextualConfig|Config $config    The bootstrap config.
  * @param Container               $container Form element container.
  * @param \Widget                 $widget    Form widget.
  *
  * @return void
  */
 private function generateUpload($config, Container $container, $widget)
 {
     $config = $config->get('form.styled-upload');
     $element = $container->getElement();
     /** @var Element $element */
     $element->addClass('sr-only');
     $element->setAttribute('onchange', sprintf($config['onchange'], $element->getId()));
     $input = Element::create('input', array('type' => 'text'))->setId($element->getId() . '_value')->addClass('form-control')->setAttribute('disabled', true)->setAttribute('name', $element->getAttribute('name') . '_value');
     if ($element->hasAttribute('placeholder')) {
         $input->setAttribute('placeholder', $element->getAttribute('placeholder'));
     } elseif ($widget->placeholder) {
         $input->setAttribute('placeholder', $widget->placeholder);
     }
     $click = sprintf('$(%s).click();return false;', $element->getId());
     $submit = Element::create('button', array('type' => 'submit'))->addChild($config['label'])->addClass($config['class'])->setAttribute('onclick', $click);
     $inputGroup = new InputGroup();
     $inputGroup->setElement($input);
     if ($config['position'] == 'left') {
         $inputGroup->setLeft($submit, $inputGroup::BUTTON);
     } else {
         $inputGroup->setRight($submit, $inputGroup::BUTTON);
     }
     $container->addChild('upload', $inputGroup);
 }
Esempio n. 2
0
 /**
  * Add input group to the form container.
  *
  * @param ContextualConfig|Config $config    The bootstrap config.
  * @param \Widget                 $widget    The form widget.
  * @param Container               $container The element container.
  * @param CastsToString           $element   The element.
  *
  * @return void
  */
 private function addInputGroup($config, $widget, Container $container, CastsToString $element)
 {
     if ($this->getWidgetConfigValue($config, $widget->type, 'input-group') && ($widget->bootstrap_addIcon || $widget->bootstrap_addUnit || $container->hasChild('submit') || $widget->type == 'captcha')) {
         $inputGroup = new InputGroup();
         $inputGroup->setElement($element);
         $container->setWrapper($inputGroup);
         $this->addIcon($widget, $inputGroup);
         $this->addUnit($widget, $inputGroup);
         $this->adjustSubmitButton($config, $container, $widget, $inputGroup);
         $this->adjustCaptcha($widget, $container, $inputGroup);
     }
 }