JQuery validation callback function

Currently, I have a form inside the light box frame on my web page. When a user submits a form with invalid data, a div appears at the top of the form with a list of form errors. The problem is this: I need something like a jQuery checkback request to resize a lightbox after a div error occurs. As far as I know, there is no way to do this in jQuery lightbox.

+6
source share
2 answers

you must specify an invalid callback function that you can find here , for example

$(".selector").validate({ invalidHandler: function(form, validator) { var errors = validator.numberOfInvalids(); if (errors) { //resize code goes here } } }) 
+17
source

Alternatively, you can use the errorPlacement callback function to act on a specific element that has not passed validation. For example, the code below uses the errorPlacement callback to set the class of each invalid tag of the parent element of a form element to "error", and then removes the "error" class after checking the element:

 form.validate({ rules: { Name: { required: true }, Email: { required: true , regex: "^[0-9a-zA-Z.+_\-] +@ {1}[0-9a-zA-Z.+_\-]+\\.+[a-zA-Z]{2,4}$" } }, messages: { Name: { required: "Please give us your name" }, Email: { regex: "Please enter a valid email address" } }, errorPlacement: function(error, element) { element.parent().addClass("error"); }, success: function(element) { $("#" + element.attr("for")).parent().removeClass("error"); } }); 
+2
source

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


All Articles