yii2comparevalidator

Yii2 compareValidator when


During user input validation I would like to compare an attribute with a value.

I have this code:

['ao_id', 'compare', 'when' => function($model) {
            return $model->lqp_id == 24 || $model->lqp_id == 26 || $model->lqp_id == 46;
        }, 'compareValue' => 50],

It works (however only when 'enableClientValidation' => false), but is it possible, to show rather the name of the foreign attribute somehow? Because it doesn't help much if the user is getting an error message that outer surface (ao_id) must be 50. Nobody has a clue what does it mean, because in the dropdown you see only the names and not the ids. Many thanks!


Solution

  • Add message key where you define your own message that will be displayed instead of default one.