Client Side Validation Triggered By Jquery.val('')

I have a form that is using client side validation (generated from a model via CActiveForm).

One of the fields is a required field but there is an instance where I want to use JQuery to clear the field.

I’m using a JQuery .val(’’) to clear the field, and as far as I can find out from JQuery documentation and a couple of tests setting the value with .val doesn’t trigger a change event… but it does trigger validation on the field!

This I believe is something happening down in yiiactiveform.js, what triggers a validation activity if it’s not a change event? And is there a way I can temporarily pause validation while I reset the field?

Validation can be triggered on change, type or submit by setting validateOnChange, validateOnType and validateOnSubmit respectively.

Check your clientOptions details to see what is enabled - http://www.yiiframework.com/doc/api/1.1/CActiveForm#clientOptions-detail

It was on validateOnChange which was mu issue. Apparently using JQuery .val(’’) to alter the contents isn’t supposed to trigger a change event but it was still causing a Yii validation. It seemed as if the yii javascript validation wasn’t using the change event but some how monitoring the content of the fields it’s self.

I’ve worked round it now and I’ve abandoned client side validation for this particular form.