Yii2 - 如何将 CSS class 添加到 ActiveForm 字段

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

这是活动表格字段。我想知道如何添加 css class 到它。

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

你可以用

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

通常,您可以在告诉 activeField 它应该是什么类型时传递 html 元素。默认值为 textInput,这就是您的代码有效的原因,但如果您想更改输入,则必须明确告诉它输入的类型。

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

<?= $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)?>