jquery Validate single-touch release verification

Source: Internet
Author: User
Tags button type

jquery Validate is a common form validation plugin. Encounter a jquery validate form validation does not trigger an issue

Current wording:
$ (function () {
$ ("#form"). Validate ({
rules: {
ThemeColor: {
required:true
            },
...
        },
messages: {
ThemeColor: {
required: ' Required ',
            },
...
        }
  });
});

<div class= "Btnwrap" >
<button type= "button" class= "btn btn-block btn-radius btn-st btn-caution submit-btn" id= "btn" > Upload
</button>
</div>

Click on the Upload button to contact the post verification, the test verification can not be triggered. Careful study of the use of the method found that the above wording can only be triggered using the submit.
<div class= "Btnwrap" >
<button type= "Submit" class= "btn btn-block btn-radius btn-st btn-caution submit-btn" id= "btn" > Upload
</button>
</div>

if you want to implement the single-touch verification on the normal button, you need to modify it slightly:
//write form validation function ValidForm, invoke validation function object within Validation button Registration button click event
function ValidForm () {
/ * Key here adds a return, which returns a validate object that has a form method that returns whether or not to pass the validation * /
return $ ("#form"). Validate ({
rules: {
ThemeColor: {
required:true
            },
...
        },
messages: {
ThemeColor: {
required: ' Required ',
            },
...
        }
  });
}
//form validation
$ (ValidForm ());
The above section has implemented the function of anonymous functions, the following describes how to implement form validation through the normal button
$ ("#btn"). Click (function () {
if (ValidForm (). form ()) {
//through form validation, write your own code below
} else {
//checksum does not pass, nothing is done, the calibration information is displayed on the form normally
    }
});

jquery Validate single-touch release verification

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.