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?