27

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

<?= $form->field($model, 'url')->label(false); ?>

2 Answers 2

40

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

Sign up to request clarification or add additional context in comments.

3 Comments

Remember that if you are using a bootstrap theme, you will probably need to add "form-control" to the css class list: 'class'=>'your class form-control'
can i add "id" fill input in textInput ? i want modify this fill input in jquery
You should be able to yes
3
<?= $form->field($addWithdrawRequest, 'amount', ['options' => ['tag' => false]])->textInput(['class' => 'form-control col-lg-6 amount','required'=>true,'style' => 'background-color: #fff !important;','placeholder'=>"Enter Amount To Withdraw"])->label(false)?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.