Answer the question
In order to leave comments, you need to log in
How to add class='error' for type='text' in case of validation error in Yii2?
Such a crutch came to mind, but it is very stupid. Tell me, please, how is it right?
<span class="block input-icon input-icon-right">
<?php
$class = [];
$error = Html::error($model, 'lname', ['tag' => 'span', 'class' => 'error']);
if (isset($error['28'])) {
$class = ['class' => 'error'];
}
?>
<?= Html::activeTextInput($model, 'lname', $class) ?>
<i class="ace-icon fa fa-user"></i>
<?= $error ?>
</span>
Answer the question
In order to leave comments, you need to log in
When using standard validation, the has-error class is already added to the field container. The class name is configured through the properties www.yiiframework.com/doc-2.0/yii-widgets-activefor...
Do you need the field itself?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question