[solved] Validate only one field via AJAX

Hi,

Im trying to do a user registration form, using CActiveForm, ajax validation and client side validation. I have read this in the user guide

But, how do i define that i want the validation only for the username? i want client side validation for all fields (that is working ok) but i want ajax validation only for username field (now, ajax validation is triggering for every field)

This is what i have:


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

	'id'=>'usuario-form',

	'enableClientValidation'=>true,

	'enableAjaxValidation' => true,

	'clientOptions' => array(

		'validateOnSubmit' => true,

	),

    'focus' => array($model, 'login'),

));

Thanks

hi

i think you should override clientValidateAttribute() and implement your own validation with Javascript.

check this : http://www.yiiframework.com/doc/api/1.1/CValidator#clientValidateAttribute-detail

Hi,

Thanks for your reply. What you say is for custom client validation, right? this is working ok.

What i want to do is trigger the ajax validation only for the username field, as described in CActiveForm documentation.

Found it:

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

So, i have to set the 4th parameter to false:

Login will trigger ajax validation:


<?php echo $form->error($model,'login'); ?>



Name will validate only in client side:


<?php echo $form->error($model,'name', array(), false); ?>

I hope this will help someone in the future.

Thanks!