0
votes

I have a view:

<?= $form->field($registration, 'username',
            ['template' => '<div class="uk-form-row">
                                <label for="register_username">{label}</label>
                                {input}{error}
                                </div>'])
            ->textInput(['class' => 'md-input']) ?>

And I want it to add new class to textInput after the error was triggered. In the model there's some rules for this input:

['username', 'string', 'min' => 2, 'max' => 255, 'message' => 'Can not be blank'],
['username','required']

And for example if I type 1 symbols that will trigger an error that will say Can not be blank. But also I want to add md-input-danger class on this input. Is there's a proper way to do that?

2

2 Answers

0
votes

You should apply some options to your Form:

$form = ActiveForm::begin([
    'layout' => 'horizontal',
    'fieldConfig' => [
        'horizontalCssClasses' => [
            'error' => 'md-input-danger'
        ],
    ],
]);
0
votes

if you want to use yii\web\ActiveField look at:

yii-widgets-activefield.html#$errorOptions-detail

Code should be like:

$form = ActiveForm::begin([
    'fieldConfig' => [
        'errorOptions' => ['class' => 'md-input-danger']
    ],
]);

P.S. Hutsi`s code uses yii\bootstrap\ActiveField