Using "when" in model rules required field validation

When using the when clause in rules/validation function in the model, I seem to always get the validation fired. My original code was:

            [['avalue'], 'required', 'when' => function ($model) {
                    return ($model->anull == 'N');

This seemed to always evaluate to making the avalue a required filed.

Then I tried these two hard-coded variations. Same results - it’s as if the when clause does not exist.

            [['avalue'], 'required', 'when' => true],
            [['avalue'], 'required', 'when' => false],

Is the client validation disabled?
I guess it’s enabled.
You have to disable it or write the whenClient option for it.

1 Like

Yes, whenClient of course! Used it before but forgot about it Thanks!