I
I
Ivan Komarov2017-08-15 11:19:14
Yii
Ivan Komarov, 2017-08-15 11:19:14

Yii2. How to cancel a validation rule for a specific element?

You need to cancel validation for specific elements under certain conditions.
I tried this way:
validation rule:

'image' => [
                ['PhotoFacet', 'PhotoProfile'], 'image', 'when' => function($model) {
                    return $model->PhotoFacet!="skip";
                },'message' => $lang["non_image"], 'notImage' => $lang["non_image"],
            ],

View code:
echo $form->field($model, 'PhotoProfile')->hiddenInput(['value' => 'skip'])->label(false);
echo $form->field($model, 'PhotoFacet')->hiddenInput(['value' => 'skip'])->label(false);

However, I still get a working rule. Why is that? Or perhaps there is another better way?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-08-15
@webinar

$lang["non_image"]- this array is very confusing, but this is so in the course of the locomotive, it should not affect.
And that's why your validation rules ended up in an array 'image' => [Show the full code of the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question