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

前端 未结 7 1863
我寻月下人不归
我寻月下人不归 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:32

    SOLUTION I USE:

    Everytime you create a new input, check if there are any errors for that field using CakePhp function isFieldError() and simply append "has-error" class to div just like i did below:

    Just div setting:

    'div' => array('class' => "form-group ".($this->Form->isFieldError('username') ? 'has-error' : '')),
    

    Full code for one field:

    Form->input(
        'username',
        array(
            'label' => array('text' => 'Username', 'class' => 'strong'), 'placeholder' => "Your Username", 'class' => 'form-control', 
            'div' => array('class' => "form-group ".($this->Form->isFieldError('username') ? 'has-error' : '') ),
            'error' => array('attributes' => array('wrap' => 'p', 'class' => 'help-block has-error'))
            )
    ); ?>
    

提交回复
热议问题