Beispiel #1
0
 public function select2(Form\Element\SelectRemote $element)
 {
     // CLASS
     $class = Style::FORM_GROUP_CLASS;
     // ERROR
     if ($hasError = !$element->getValidator()->isValid()) {
         if (empty($element->getAttribute('data-placement'))) {
             $element->addAttribute('data-placement', 'bottom');
         }
         $message = '';
         foreach ($element->getValidator()->getErrors() as $error) {
             $message .= $error . ' ';
         }
         $element->addAttribute('data-original-title', $message);
         $element->addAttribute('data-toggle', 'tooltip');
         $class .= ' ' . Style::FORM_GROUP_ERROR;
     }
     // LABEL
     $label = '';
     if ($element->getForm()->hasLabel()) {
         $label = '<label for="' . $element->getName() . '" class="col-md-3 control-label">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
     }
     // INPUT
     $element->addClass('select2-remote');
     $element->addAttribute('data-css', 'form-control input-large input-sm');
     $element->addAttribute('data-remote', $element->getUrl());
     $element->addAttribute('data-length', $element->getLength());
     $element->addAttribute('placeholder', $element->getLabel());
     $element->addAttribute('id', $element->getName());
     $html = html('input', $element->getAttributes());
     // DESCRIPTION
     if ($element->hasDescription()) {
         $html .= html('span', ['class' => 'help-block'], $element->getDescription());
     }
     // FINAL CONTAINER
     $html = html('div', ['class' => 'col-md-9'], $html);
     return html('div', compact('class'), $label . $html);
 }
Beispiel #2
0
 public function select2(Form\Element\SelectRemote $element)
 {
     // Error
     if ($hasError = !$element->getValidator()->isValid()) {
         $element->removeAttribute('data-trigger');
         //Si il y avait un popoover au départ on le surcharge par un tooltip
         if (empty($element->getAttribute('data-placement'))) {
             $element->addAttribute('data-placement', 'bottom');
         }
         $message = '';
         foreach ($element->getValidator()->getErrors() as $error) {
             $message .= $error . ' ';
         }
         $element->addAttribute('data-original-title', $message);
         $element->addAttribute('data-toggle', 'tooltip');
     }
     // rendu principal
     $element->addClass(Style::FORM_ELEMENT_CONTROL);
     $label = '';
     if ($element->getForm()->hasLabel()) {
         $label = '<label for="' . $element->getName() . '">' . $element->getLabel() . ($element->hasRule('required') ? ' *' : '') . '</label>';
     }
     $element->addClass('select2-remote');
     $element->addAttribute('data-remote', $element->getUrl());
     $element->addAttribute('data-length', $element->getLength());
     $element->removeClass('form-control');
     $html = $label . html('input', $element->getAttributes());
     $class = Style::FORM_GROUP_CLASS;
     if ($hasError) {
         $class .= ' ' . Style::FORM_GROUP_ERROR;
     }
     $html = html('div', compact('class'), $html);
     return $html;
 }