Search code examples
phptwitter-bootstrapyii2yii2-advanced-appbootstrap-material-design

How to Customizing/add a class to the ActiveForm items with Material Bootstrap design classes on Yii2


I'm trying to add a class for a TextField like this one:

<div class="form-group-lg">

                    <?= $form->field($model, 'email'); ?>

                </div>

Output:

enter image description here

And that would be something like this?(the label will be inside the TextField).i mean, can we use it like below codes?

Example:

I need something like this:

<div class="form-group label-floating">
  <label class="control-label" for="focusedInput1">Write something to make the label float</label>
  <input class="form-control" id="focusedInput1" type="text">
</div>

http://fezvrasta.github.io/bootstrap-material-design/bootstrap-elements.html

Forms section-first one.

So, the question is,

How can i add a class to this item with above codes on Yii2 ActiveForm?


Solution

  • You need to use fieldConfig Propertie in ActiveForm.

    Like as

    <?php $form = ActiveForm::begin([
        'id' => 'active-form',
        'fieldConfig' => [
            'template' => "<div class=\"form-group label-floating\">{label}{input}{error}</div>",
        ],
    ]); ?>
    

    For more info read Docs