Resolve Jquery.validate.js Validation Bugs

Source: Internet
Author: User

Version hint: JQ is 1.4.4, Jquery.validate is jquery validation plug-in 1.7

Problem:

A. Optional options, such as mailbox format verification, then the case input box, verify that the label becomes blank "The original default hint is gone"

B. Required options, such as mobile phone number directly copied in, the format is right, verify that the label is unchanged

1. master Page

$ (function () {$.validator.setdefaults ({errorclass:"Tip-error", errorplacement:function (Error, Element) {Error.prependto (element.parents ("TD"). Next ()); Objerror.removeclass ("Btn_infomust");                objerror.html (Error); }, Success:function (Element) {element.html ("correct"). AddClass ("tip-success"); }            });});

2. Sample form page code

<tr> <th scope="Row">Mobile Number:</th> <td>@Html. Textboxfor (t= T.phoneno,New{@Style ="width:200px", maxlength =" -" })                    </td> &LT;TDclass="slight"> <labelclass="Btn-infomust"> Required fields. </label> </td> </tr> <tr> < Th scope="Row">e-mail address:</th> <td>@Html. Textboxfor (t= T.email,New{@Style ="width:200px", maxlength =" -" })                    </td> &LT;TDclass="slight"> <spanclass="Btn-info"> Optional fields. </span> </td> </tr>

3.jquery.validate.js File Code

Solution: Note that the code is written to death, the need to change according to their own

 //before and after 360 linesif(element.value==""){if(Element). Rules (). Required! =true&&$ (Element). Rules (). Required! =false) {$ (Element). Parents ("TD"). Next ("TD"). HTML ('<label class= "Btn-info" > Optional. </label>');}} Element:function (Element) {//default prompt is restored when rule required does not exist        if(Element.value = ="") {            if(Element). Rules (). Required! =true&& $ (Element). Rules (). Required! =false) {$ (Element). Parents ("TD"). Next ("TD"). HTML ('<label class= "Btn-info" > Optional. </label>'); }         }               returnresult; }    //before and after 670 linesshowlabel:function (element, message) {//Replace label manually$ (Element). Parents ("TD"). Next ("TD"). HTML (label);        Console.log (label);  This. Toshow = This. Toshow.add (label); },

Resolve Jquery.validate.js Validation Bugs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.