R
R
Roma Antonyuk2017-06-08 09:58:24
Yii
Roma Antonyuk, 2017-06-08 09:58:24

How to change error display location in yii2?

i have two fields

<div class="date-range">
                                <?= $form->field($model, 'date_from', [
                                    'options' => [
                                        'class' => 'date-control form-group',
                                    ]
                                ])->textInput([
                                    'class' => 'form-control date-range-start empty',
                                    'placeholder' => Yii::t('main', 'there')
                                ])->label(false) ?>
                                <?= $form->field($model, 'date_till', [
                                    'options' => [
                                        'class' => 'date-control form-group'
                                    ],
                                ])->textInput([
                                    'class' => 'form-control date-range-end empty',
                                    'placeholder' => Yii::t('main', 'back')
                                ])->label(false) ?>
                            </div>

and there is a block in which you need to display errors
<div class="message-block"></div>
, is it possible to set a class where to display messages?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmirogin, 2017-06-08
@dmirogin

<?= $form->field($model, 'date_from', [
      'options' => [ 'class' => 'date-control form-group',],
      'errorOptions' => ['tag' => 'span', 'class' => 'has-error__text']
])?>

M
Maxim Timofeev, 2017-06-08
@webinar

error display class

somewhere 3rd. "class" instead of "class" and "zhi" write "shi" with the letter "and"
Now about yii2:
here are the activeForm docs:
www.yiiframework.com/doc-2.0/yii-widgets-activefor...
There is a public property errorCssClass (added to the error group) and errorSummaryCssClass (block class with error text)
So somewhere like this:
<?php $form = ActiveForm::begin([
'errorSummaryCssClass' => 'someMyClass'
]); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question