client side validation not working after submitting form via ajax

After I have submitted a form via Ajax the client side validation is not working anymore.

I have already tried to prevent reloading jquery.js but it didn’t help.

Here the test with an Yii skeleton, nearly unmodified, just ajax support added.

Controller action:


I am seeing the same thing, its particularly ugly since the form will still submit with errors, but returned via Ajax displaying the errors, yet when you fill the form correctly the error display does not change… all pink and red! :-X

Now I have a solution (with help of the IRC):

You have to use renderPartial($view,$params,false,true); (the last parameter causes including the inline JS to the renderPartial(), so that the event listeners are renewed).

Furthermore you should consider, that some scripts will be double loaded, for example YiiActiveForm, which you can disable via Yii::app()->clientScript->scriptMap[$file] = false;

Now it’s working well, but it is not nice, that you have always to load the inline script, it’s pretty much, if you use some validators, it would be nice, if you could reuse it from the first load, but I have very limited JS knowledge.

Thanks for the tip, I knew it would be something simple.