Example #1
0
 /**
  * Set bootstrap select element attributes..
  *
  * @param ContextualConfig|Config $config  The config.
  * @param Element                 $element The select element.
  * @param \Widget                 $widget  The widget.
  *
  * @return void
  */
 private function setStyledSelectAttributes($config, $element, $widget)
 {
     $element->addClass($config->get('form.styled-select.class'));
     $element->setAttribute('data-style', $config->get('form.styled-select.style'));
     $size = $config->get('form.styled-select.size');
     if ($size !== 'auto') {
         $element->setAttribute('data-size', $size);
     }
     if ($widget->bootstrap_select_search || $this->hasExceededOptionsThreshold($config, $widget)) {
         $element->setAttribute('data-live-search', 'true');
     }
     $format = $config->get('form.styled-select.selected-text-format');
     if ($widget->multiple && $format) {
         $element->setAttribute('data-selected-text-format', html_entity_decode($format));
     }
     // If a btn-* class isset, set it as data-style attribute.
     $classes = explode(' ', $widget->class);
     foreach ($classes as $class) {
         if (strpos($class, 'btn-') === 0) {
             $element->removeClass($class);
             $element->setAttribute('data-style', $class);
             break;
         }
     }
 }
 /**
  * Apply the form control.
  *
  * @param ContextualConfig|Config $config    The bootstrap config.
  * @param Element                 $element   Current form element.
  * @param \Widget                 $widget    The form widget.
  * @param Container               $container The container.
  *
  * @return void
  */
 private function applyFormControl($config, $element, $widget, Container $container)
 {
     // apply form control class to the element
     if ($this->getWidgetConfigValue($config, $widget->type, 'form-control', true)) {
         $element->addClass('form-control');
         if ($container->hasChild('repeat')) {
             /** @var Element $repeat */
             $repeat = $container->getChild('repeat');
             $repeat->addClass('form-control');
         }
     }
 }