The 'When' property of the Validator object doesn't work

In the next code the ‘When’ property is ignored and entry of the ‘delegate’ field is ALWAYS required regardless of the value of the function result in the When property:

['delegate', 'required', 'when' => function($model) {
                return $model->thereIsDelegation == 1;}] 

even if in the function I always return ‘false’ the result is the same

['delegate', 'required', 'when' => function($model) {
                return false;}] 

What’s wrong?
Thanks

Hi @FabioFabio

Probably it is required in the client side validation.

Try disabling the client side validation and see if it works or not.
And consider writing “whenClient” property.

ok thanks, but do you know how I can disable client-side validation (also because I have not explicitly enabled it)?

Default in ActiveForm, enabled.
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activeform#$enableClientValidation-detail

Perfect, I solved! It was the client-side validation that needed to be “fixed”, thank you very much!