Jquery extension for checking / hiding a div or clearing a div after checking

To clarify how to run a custom function right before the jquery validation plugin launches its validation function (what is it that looks at all fields and shows an error message)?

Now I have all my errors displayed in a div. Eid wanted to catch the validation event and clear the div before it triggered my old errors. Then id would like to show / hide this div based on whether there are any tags in it that were automatically generated by the jquery validation plugin. I can do everything except figure out how to extend the event, run the material I need, and then call the validation function. Thank!

+2
source share
2 answers

There are 2 properties for this: errorContainerand errorLabelContainer, for example, you need a list of errors in <div>and <div>to hide / show based on, if any, you would do this:

$("#myform").validate({
   errorContainer: "#myDivID",
   errorLabelContainer: "#myDivID ul",
   wrapper: "li",
   //other options/rules...
});

The parameters page contains more detailed information about this , but all you need for a simple fix, provided that the list is what you have, from the question I was not quite sure. If you want to say divs inside your div, no sweat ... just change "#myDivID ul"to "#myDivID"and "li"to "div"... or whatever element you want.

<div id="myDivID">, , , . , / - div, - div, errorLabelContainer... / / .

+1

, . success invalidHandler , errorPlacement .

. http://docs.jquery.com/Plugins/Validation/validate#toptions.

0

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


All Articles