Answer the question
In order to leave comments, you need to log in
Why doesn't the activeForm custom rule work?
There is a form with a field (there are other fields, but it does not apply to the topic):
<?=$form->field($model,'date', ['enableAjaxValidation' => true, 'enableClientValidation' => false])->input('date');?>
public function rules()
{
return [
['date', 'date', 'format' => 'php:Y-m-d'],
['date', 'checkDate'],
];
}
public function checkDate($attribute, $param) {
$this->addError('date', 'Значение: '.$this->$attribute);
}
Answer the question
In order to leave comments, you need to log in
In the controller action add
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question