Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 - How To Add a CSS class to an ActiveForm Field

Tags:

This is the activeform field. I would like to know how to add a css class to it.

<?= $form->field($model, 'url')->label(false); ?> 
like image 931
Omar Tariq Avatar asked Mar 11 '15 19:03

Omar Tariq


1 Answers

You can add it with

<?= $form->field($model, 'url')->textInput(['maxlength' => 255, 'class' => 'your class'])->label(false); ?> 

As a rule you can pass html elements when telling activeField what type it should be. The default is textInput so that is why your code works, but if you want to change the input then you have to explicitly tell it the type of input.

http://www.yiiframework.com/doc-2.0/guide-input-forms.html

like image 89
Mihai P. Avatar answered Sep 23 '22 20:09

Mihai P.