Answer the question
In order to leave comments, you need to log in
Yii2 custom validation in Activeform - how to display an error message?
There is an Activeform with an offer_maximum field that needs to be checked...
public function rules()
{
return [
...
[ 'offer_minimum', 'number', 'min' => 100],
['offer_maximum', 'getPossibleMaximum'],
];
}
public function getPossibleMaximum($attribute){
$this->addError($attribute, 'Недостаточно средств на балансе!');
}
Answer the question
In order to leave comments, you need to log in
1. do not call the validator as a getter,
"possibleMaximum" is a good option
"checkPossibleMaximum" is also
"
getPossibleMaximum" - not correct
the model is transferred.
So
public function getPossibleMaximum($attribute){
$this->addError($attribute, 'Недостаточно средств на балансе!');
}
public function possibleMaximum($modelKakNeNazovi,$attributeHotTiTresni){
$this->addError($attributeHotTiTresni, 'Недостаточно средств на балансе!');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question