I have this in my action to validate an ajax post
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())){
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
in my view
<?php
$form = ActiveForm::begin([
'id' => $model->formName().'-form',
'action' => Url::to(['/payment/stripe/payment-session']),
'scrollToError' => false,
'validateOnSubmit' => true,
'enableAjaxValidation' => true
]);
echo $form->field($model, 'number')->textInput([ 'class' => 'form-control form-control-lg text-uppercase', 'placeholder'=>'Enter Number', 'id' => 'reports-number'])->label(false);
....
....
ActiveForm::end();
?>
in my model
public function rules() {
...
[['number'], ENumberValidator::class, 'on' => ['check-number']],
...
}
when i enter 456!!
in the input, i get this ajax returned, which is correct.
{
"reports-number": [
"Number is an invalid format."
]
}
but for some reason no error message shows under the input, the input has a check mark in green and form can still be submitted. Any idea what i’m missing here? Thanks