If using :remote=>true in form_for, jquery livevalidations shows error messages, But form get submitted

169 views Asked by At

I am using jquery livevalidations for my form, and also using :remote => true for this form. While I am submit form, livevalidations shows me errors for fields but then also form get submitted. And then due to server side validations action get rollback.

Livevalidations are not works if I am using :remote => true to any form.

1

There are 1 answers

0
Nitin On

From your description it is clear that your form validations working properly. But as you have button submit in your form then although validation failed it get submitted.

You need to remove submit button from your form and make it simple button. On click of that simple button you need to validate fields and if all good then submit form from your jquery code. And if You don't have all fields properly validated then you need to return false.

You can also use preventDefault() function in your jquery validation part to restrict form to get submitted.

If you are not going to provide older versions browsers then you can simply use html5 validations. You just need to put require => true in your view and you are done.