I’m wanting to trigger the validation of an attribute whenever another attribute on the form is changed.
I tried
'onchange' => '$("#projects").yiiActiveForm("validateAttribute", "projects-imessageid");',
but this generates the following error that I simply do not understand
Uncaught TypeError: $(…).data(…) is undefined
Can anyone help?
I also tried simply validating the entire form
'onchange' => "$('#projects').data('yiiActiveForm').submitting = true;$('#projects').yiiActiveForm('validate');",
but that gives the same error.
To give a little context, the reason I’m needing to do this is because I’m using a conditional required rule
['IMessageId', 'required', 'when' => function($model) {
return (($model->source->Source == 'E-mail') || ($model->source->Source == 'Website'));
}, 'whenClient' => "function (attribute, value) {
return (($('#projects-sourceid option:selected').text() == 'E-mail') || ($('#projects-sourceid option:selected').text() == 'Website'));
// return ($('#projects-sourceid').val() == 1);
}"],
and the validation of the attribute does not get reset/reevaluated in the form when the dependent attribute is changed, to my surprise.