Validation Rules in modal form

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 !

yii checks for header by default to determine if a call is ajax


$_SERVER['HTTP_X_REQUESTED_WITH']

do you get any client side errors in your browser console

According to docs "id", "options" and "enableAjaxValidation" are all properties (same level).

See this example.

No - There are no errors at all

Oh yes - My error - Thanks a lot!