Prevent focusing on the field when it has failed the test

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

In my current project, I have a form that is really long, and when you press the submit button, your scroll goes into the field (perhaps because it focuses), but when my form takes so long, I think it is a bit annoying. Does anyone know how I can turn off jQuery validation if I pay attention to invalid input fields.

Respectfully!

+6
source share
4 answers

Use the focusInvalid parameter and set it to false :

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

Working example here and Documentation here (options tab)

+18
source
 $('#frmTableDate').validationEngine({ focusFirstField: false }); 

if we use the Validation Engine plugin to check

0
source
 $("#myform").validate({ onfocusout: false, invalidHandler: function(form, validator) { var errors = validator.numberOfInvalids(); if (errors) { validator.errorList[0].element.focus(); } } }); 
0
source
  • Go to the jQuery validation file file (http://jquery.bassistance.de/validate/jquery.validate.js)
  • Use Control and F to find
  • Remove .focus() on line 431.
-4
source

Source: https://habr.com/ru/post/913128/


All Articles