How to modify wrapper div error class when using CakePHP with Bootstrap

前端 未结 7 1890
我寻月下人不归
我寻月下人不归 2021-02-08 13:47

I\'m using Bootstrap 3.0RC1 with CakePHP 2.3.6. Trying to take advantage of those beautiful looking classes like has-error and has-w

7条回答
  •  我寻月下人不归
    2021-02-08 14:26

    I use a custom Helper that is tailored to whatever the CSS framework is. In this case Bootstrap.

     'form-control', 'div'=>false, 'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-block')));
    
            if (isset($options['label'])) {
                if (is_array($options['label'])) {
                    $options['label'] += array('class' => 'control-label');
                } else {
                    $options['label'] = array('text' => $options['label'], 'class' => 'control-label');
                }
            } else {
                $options['label'] = array('class' => 'control-label');
            }
    
            $divOptions = array('class' => "form-group has-feedback");
            if (isset($options['div'])) {
                if (is_array($options['div'])) {
                    $divOptions += $options['div'];
                }
            }
            $options['div'] = false;                
    
            $divText = $this->Form->input($fieldName, $options);
    
            if ($this->Form->isFieldError($fieldName)) {
                $divOptions['class'] = "form-group has-error has-feedback";
                $divText .= $this->Html->tag('span', null, array('class' => "glyphicon glyphicon-remove form-control-feedback"));
            }
    
            return $this->Html->tag('div', $divText, $divOptions);
        }
    
    }
    
    ?>
    

    Then use this instead of the standard Form helper

    echo $this->UI->textBox('email'));
    

提交回复
热议问题