'when' condition in rules on model always returns true

I’m pretty darn stumped by this one.

I have a simple form model. At the user settings level, they can toggle a boolean yes/no on whether a certain field is required. Simple enough!

So in my forms model I have:

    public function rules()
    {
        return array_merge_recursive(parent::rules(), [
            .....
            ['last_steps_note', 'filter', 'filter' => 'trim' ],
            ['next_steps_note', 'filter', 'filter' => 'trim' ],
            ['escalation_reason_id', 'required', 'when' => function($model) {
                d("value: " . ($model->user->teams_require_escalation_reason ? "true" : "false"));
                return $model->user->teams_require_escalation_reason;
            }]
        ]);
    }

No matter what I do, if the “required when” is in there, regardless of the value of user->teams_require_escalation_reason, the field is required. If I remove that single rule, then it is NOT required.

What’s weird is that I never see the output of the debug statement! I even tried disabling view side validation to be safe:

$form = ActiveForm::begin([
    'enableAjaxValidation' => false,
]);

Any ideas how to debug this?

Quick update, I even tried this:

            ['last_steps_note', 'filter', 'filter' => 'trim' ],
            ['next_steps_note', 'filter', 'filter' => 'trim' ],
            ['escalation_reason_id', 'required', 'when' => function($model) {
                d("hi!");
                d("value: " . ($model->user->teams_require_escalation_reason ? "true" : "false"));
                return false;
                //return $model->user->teams_require_escalation_reason;
            }]

Try adding whenClient part also for client validation.

Interesting. I thought this DISABLED client-side validation though? Am I using this incorrectly?

$form = ActiveForm::begin([
    'enableAjaxValidation' => false,
]);

Client side validation differs from AjaxValidation.
Try adding enableClientValidation => false.