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


i'm using bootstrap 3.0rc1 cakephp 2.3.6. trying take advantage of beautiful looking classes has-error , has-warning validation states, need change default element class formhelper adds wrapping div.

so far i'm using code:

echo $this->form->create('user', array(     'inputdefaults' => array(         'class' => 'form-control',         'div' => array('class' => 'form-group'),         'label' => array('class' => 'control-label'),         'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-block'))     ) ));   echo $this->form->input('email')); 

which output on error:

<div class="form-group error">     <label for="useremail" class="control-label">email</label>     <input name="data[user][email]" class="form-control form-error" type="email" value="a@a.com">     <span class="help-block">email in use.</span> </div> 

everything fine, except need change error class in wrapping div has-error, new styles applied label, input , span. couldn't find clean solution far.

the ugly solution thought copy has-error styles bootstrap error class in app.

if introspect formhelper, you'll find in line "ugly" code error magic.

since original authors did not leave chance configuration, i'm suggesting writing own bootstrapformhelper, , override input function, changing single line.

here snippet:

//inside public function input($fieldname, $options = array())  $out['error'] = null; if ($type !== 'hidden' && $error !== false) {     $errmsg = $this->error($fieldname, $error);     if ($errmsg) {         $divoptions = $this->addclass($divoptions, 'has-error'); //old string value 'error'         if ($errormessage) {             $out['error'] = $errmsg;         }     } } 

since i'm using custom bootstrapformhelper, here link full gist.

just copy file app\view\helper, , add all controllers line:

public $helpers = array(   'form' => array('classname' => 'bootstrapform') ); 

assuming you've saved gist bootstrapformhelper.php.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -