[[+content_image]]
A
A
AlexAll2019-02-09 10:41:07
Yii
AlexAll, 2019-02-09 10:41:07

Why doesn't check for required fields work in yii2?

Why doesn't check for required fields work in yii2? The model has a rule

public function rules()
    {
        return [
            [['title'], 'required'],

in view form
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

in the source code, you can see that the field is required
<div class="form-group field-news-title required">
<label class="control-label" for="news-title">Заголовок</label>
<input type="text" id="news-title" class="form-control" name="News[title]" maxlength="255" aria-required="true">

<div class="help-block"></div>
</div>

But nothing works, you leave the title empty and click save, no warning pops up that this field is not filled.
What could be the reason?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Andrey, 2019-02-09
@VladimirAndreev

Specify that the field cannot be empty.

M
Maxim Timofeev, 2019-02-09
@webinar

Look at the console, what's there., maybe js errors. Perhaps the field is not empty, perhaps the validation scripts did not connect at all or do not see the selectors. A million options. It's hard to tell from this description what exactly happened.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question