Answer the question
In order to leave comments, you need to log in
How to highlight multiple fields in yii2 for one validation error?
Is it possible to highlight several related fields at once while validating the active form, displaying only one error??
Answer the question
In order to leave comments, you need to log in
In Yii1, the logic was as follows: validation is assigned to one of the fields through a class method in which errors are set for several fields at once.
public function rules () {
return [
['field1', 'customValidate'],
];
}
public function customValidate ($attribute, $params) {
if (some_expression) {
$this->addError('field1', 'Error description');
$this->addError('field2', '');
$this->addError('field3', '');
}
}
public function rules () {
return [
[
'field1',
function($attribute, $params){
if (some_expression) {
$this->addError('field1', 'Error1 description');
$this->addError('field2', '');
$this->addError('field3', '');
}
}
],
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question