jquery.validata1.11 How to support metadata

Source: Internet
Author: User

Using the Metadata method
This requires the use of the Jquery.metadata.js plugin to work, specifying validation rules by defining special properties in the form item

But I found that the latest Jquery.validate 1.11 has no built-in metadata support, so it needs to be modified

Search for $.validator.classrules (element) in the Jquery.validate.js file and add the following line before it:

$.validator.metadatarules (Element),

Then search staticrules:, add the following code in front of it, add metadata support:

Metadatarules:function (Element) {

if (!$.metadata) return {};

var meta = $.data (element.form, ' Validator '). Settings.meta;

Return meta?

$ (Element). metadata () [meta]:

$ (Element). metadata ();

},

Here, the transformation is complete, to use metadata, the page uses the following methods (omitting other code):

<script src= "Lib/jquery.js" type= "Text/javascript" ></script>

<script src= "Lib/jquery.metadata.js" type= "Text/javascript" ></script>

<script src= "Lib/jquery.validate.js" type= "Text/javascript" ></script>

<form>

<input name= "User" class= "{required:true,minlength:3}"/>

</form>

However, the default class is used to define the CSS style class name, which is used as a validation rule to create too much inconvenience to the style maintenance, there are two ways to solve the problem:

A. Modifying jquery.metadata.js directly, type modified to attr, name modified to validate, indicating the validation rule obtained from the Validate property of the form item

B. Call $.metadata.settype (' attr ', ' Validate ') in the page header to obtain the validation rule from the Validate property of the form item

-----Excerpt: http://www.55dream.cn/code/javascript/466.html

jquery.validata1.11 How to support metadata

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.