Exemple #1
0
 /**
  * Inpout text rendrer
  *
  * @param \FrenchFrogs\Form\Element\Text $element
  * @return string
  */
 public function text(Form\Element\Text $element)
 {
     // CLASS
     $class = Style::FORM_GROUP_CLASS . ' row';
     // 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(Style::FORM_ELEMENT_CONTROL);
     $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);
 }
Exemple #2
0
 public function text(Form\Element\Text $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
         $element->addClass('form-error');
         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>';
     }
     $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;
 }