Here's what you can do:
- By default the validate plugin focuses the first erroneous element (in case there's any). Turn off the optionfocusInvalidby setting it tofalse.
- The callbackinvalidHandlerhandler is executed when the form is invalid. You get access through the second parametervalidatorto the validator object and thus to the errorList array. You can then animate the scroll relatively to the first erroneous element.
Here's the code:
$("#commentForm").validate({
    focusInvalid: false,
    invalidHandler: function(form, validator) {
        if (!validator.numberOfInvalids())
            return;
        $('html, body').animate({
            scrollTop: $(validator.errorList[0].element).offset().top
        }, 2000);
    }
});Source: https://stackoverflow.com/questions/9392133/when-form-is-validated-how-to-scroll-to-the-first-error-instead-of-jumping
 
 
 
No comments:
Post a Comment
Please Comment Here!