Ajax Validation On Custom Rule

How to add custom validation rule on ajax form validation.

return array( array(‘to’, ‘compareDateRange’,‘message’=>‘To date can not be less than from date.’),

         );

public function compareDateRange($attribute,$params) {

        if(strtotime($this->attributes['to']) < strtotime($this->attributes['from'])) {


            $this->addError($attribute,$params['message']);


        }


    }

How can i display the error message return from compareDateRange() instantly on form?

Hi,

Just bind error with attribute

in controller

addError(‘attributename’,‘messages…’)

in view

form->error(‘attributename’)