Hello
I have seen Yii2 doc and examples about enableAjaxValidation but I can’t make it work
( http://www.yiiframework.com/doc-2.0/guide-input-validation.html )
It seems to me that Yii::$app->request->isAjax is always FALSE.
Are there requirements to use this functionnality ?
here my code (generated by crud and modified :
_form :
<?php $form = ActiveForm::begin(
['options' =>
[
'id' => 'create-update-country-form',
'enableAjaxValidation' => true,
]
]); ?>
controller :
...
use yii\widgets\ActiveForm; // Ajaxvalidation
use yii\web\Response; // Ajaxvalidation
...
public function actionCreate()
{
$model = new Country();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', Yii::t('app', 'success.create'));
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Thanks !