Exemplo n.º 1
0
 public function textarea(Form\Element\Textarea $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');
     }
     $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('textarea', $element->getAttributes(), $element->getValue());
     $class = Style::FORM_GROUP_CLASS;
     if ($hasError) {
         $class .= ' ' . Style::FORM_GROUP_ERROR;
     }
     $html = html('div', compact('class'), $html);
     return $html;
 }
Exemplo n.º 2
0
 /**
  * Textarea render
  *
  * @param \FrenchFrogs\Form\Element\Textarea $element
  * @return string
  */
 public function textarea(Form\Element\Textarea $element)
 {
     // CLASS
     $class = Style::FORM_GROUP_CLASS . ' row';
     /// ERROR
     if ($hasError = !$element->getValidator()->isValid()) {
         $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);
         $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('textarea', $element->getAttributes(), $element->getValue());
     // 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);
 }