示例#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);
 }
示例#2
0
 /**
  * @param $widget
  * @param $container
  * @param $element
  */
 private function addInputGroup($widget, Container $container, CastsToString $element)
 {
     if ($this->getConfig($widget->type, 'allowInputGroup') && ($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($container, $widget, $inputGroup);
         $this->adjustCaptcha($widget, $container, $inputGroup);
     }
 }