contact

Archive for October 14th, 2008

jquery ajaxForm and validate with ajaxSubmit()

Tuesday, October 14th, 2008

I am currently working my way into the jquery universe and I really like the great plugins that take a lot of the workload of off your back. I am developing an application that uses the ajaxForm plugin and it worked nicely. Then I implemented the also great validate plugin and it for it self also worked really well.

The problem:

it seems that the ajaxForm keeps getting submitted with or without errors using the ajaxForm submission and if the form contains no errors it gets submitted a second time via this method discribed by the plugin author:

</pre>
submitHandler: function(form) {
jQuery(form).ajaxSubmit({
target: "#result"
});
}
<pre>

The solution / workaround:

I found the only way to get this work is to completly ignore the submitting capabilities of the validate plugin and use the ajaxForms built in beforeSubmit option to check the form using the validate valid() function.

</pre>
beforeSubmit:checkForm // add this to your ajaxForms options

function checkForm(data,form){ // this method will tell the beforSubmit method if the form is valid
 return $(form).valid();
 }
<pre>

note: I have