Hello,
I want to apply a validation rule only if other field has been changed. In the Controller I can see if one field are changed looking at dirty array, but I can’t found how to do that in the Table. I want to validate the typical “password repeat situation”, where the validation of the password_repeat field only is needed if the password field has been changed:
$validator
->scalar('password')
->requirePresence('password')
->notEmpty('password');
$validator
->add('password_repeat', 'comparePasswords', [
'rule' => ['compareWith', 'password'],
'message' => __('Different password repeat'),
'on' => function ($context) {
// Some code to detect if the password field are changed
return true;
}
]);
Can you give me some tip?
Thanks in advance.