I have tried following this https://github.com/samdark/yii2-cookbook/blob/master/book/forms-validator-multiple-attributes.md Unfortunately, it already has an issue raised that it no longer works with updates to Yii2 and I can't find any way to make it work.
I have two attributes which must be unique from each other. (Both are an array of strings.)
My validation logic works, but I can't find a way to display errors (or remove errors) on both attributes at the same time.
I have tried making a custom validator class, and also an inline validator, with the same problem:
When entering data in the form, only the attribute being edited will have its error message updated.
Below is the simplest version of my code that doesn't work, I want to display an error on both attributes after editing either one of them.
public function rules()
{
return [
[['attribute1', 'attribute2'], 'customValidator'],
];
}
// declare validator
public function customValidator($attribute, $params)
{
$this->addError('attribute1', 'error');
$this->addError('attribute2', 'error');
}