performAjaxValidation in CActiveForm

I set up my form and controller as described here: http://www.yiiframework.com/doc/api/CActiveForm#enableAjaxValidation-detail


public function actionCreate()

{

	$model=new Product;

		

	$this->performAjaxValidation($model);


	if(isset($_POST['Product']))

	{

        	$model->attributes=$_POST['Product'];

        	if($model->save())

            		$this->redirect('index');

	}


	$this->render('create', array('model'=>$model));


}


protected function performAjaxValidation($model)

{

	if(isset($_POST['ajax']) && $_POST['ajax']==='product-form')

	{

		echo CActiveForm::validate($model);

		Yii::app()->end();

	}

}


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'product-form',

	'enableAjaxValidation'=>true,

)); ?>

But Ajax validation does not get performed.

Actually my mistake - the validation does get performed but only when the field loses focus - I was under the impression it would do it when the submit button is pressed - any way to make it work this way?




<?php $form=$this->beginWidget('CActiveForm', array(

  'id'=>'product-form',

  'enableAjaxValidation'=>true,

  'validateOnSubmit'=>true,

  'validateOnChange'=>false,

  'validateOnType'=>false,

)); ?>



More info here:

http://www.yiiframework.com/doc/api/CActiveForm#clientOptions-detail

(not tested)

/Tommy


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'product-form',

	'enableAjaxValidation'=>true,

	'clientOptions'=>array('validateOnSubmit'=>true, 'validateOnChange'=>false),

)); ?>

This works OK, apart from that when the submit button is pressed it doesn’t scroll up to the error summary, or to the first input error.