Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent focus on field when it fails validation

I often use this jQuery validation plugin to validate forms and it works great. Really pleased with it, but when you press Submit on a form it automatically puts focus on the field that was invalid.

On my current project I have a form wich is really long, and when you press the submit button, your scroll jumps up to the field (probably because it gets focused), but when my form is this long i think it's a bit annoying. Does anyone know how i can disable jQuery validate from putting focus on invalid input fields.

Best regards!

like image 204
Paparappa Avatar asked Apr 13 '12 12:04

Paparappa


1 Answers

Use the focusInvalid option and set it to false :

$("#abc").validate({
  focusInvalid: false
});

Working example here and Documentation here (options tab)

like image 149
Manse Avatar answered Sep 27 '22 22:09

Manse