Paparappa Paparappa - 1 year ago 49
jQuery Question

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!

Answer Source

Use the focusInvalid option and set it to false :

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

Working example here and Documentation here (options tab)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download