L
L
Lomoson2015-04-07 13:39:03
Yii
Lomoson, 2015-04-07 13:39:03

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>

In the first version, there were no such problems, but here xs how to do it (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Makarov, 2015-04-07
@Lomoson

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 question

Ask a Question

731 491 924 answers to any question