Skip to content

Commit

Permalink
Remove support for metadata plugin, replace with data-rule- and data-…
Browse files Browse the repository at this point in the history
…msg- (added in 907467e) properties.
  • Loading branch information
mlynch authored and jzaefferer committed Nov 23, 2012
1 parent 5ec962e commit 6df33a8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 200 deletions.
Expand Up @@ -8,18 +8,16 @@

<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../jquery.validate.js" type="text/javascript"></script>
<script src="../lib/jquery.metadata.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
$("#commentForm").validate({meta: "validate"});
$("#commentForm2").validate();
$("#commentForm3").validate({
$("#commentForm").validate();
$("#commentForm2").validate({
messages: {
email: {
required: 'Enter this!'
}
}
}
});

});
Expand All @@ -28,54 +26,41 @@
<style type="text/css">
form { width: 500px; }
form label { width: 250px; }
form label.error,
form label.error,
form input.submit { margin-left: 253px; }
</style>

</head>
<body>

<h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jQuery Validation Plugin</a> Demo</h1>
<div id="main">

<p>Take a look at the source to see how messages can be customized with metadata.</p>
<p>Take a look at the source to see how messages can be customized with metadata.</p>

<!-- Custom messages with custom "meta" setting -->
<!-- Custom rules and messages via data- attributes -->
<form class="cmxform" id="commentForm" method="post" action="">
<fieldset>
<legend>Please enter your email address</legend>
<p>

<label for="cemail">E-Mail *</label>
<input id="cemail" name="email" class="{validate:{required:true, email:true, messages:{required:'Please enter your email address', email:'Please enter a valid email address'}}}"/>
<input id="cemail" name="email" data-rule-required="true" data-rule-email="true" data-msg-required="Please enter your email address" data-msg-email="Please enter a valid email address" />
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
</fieldset>
</form>
<!-- Custom messages with default "meta" setting -->
<form class="cmxform" id="commentForm2" method="post" action="">
<fieldset>
<legend>Please enter your email address</legend>
<p>

<label for="cemail">E-Mail *</label>
<input id="cemail" name="email" class="{required:true, email:true, messages:{required:'Please enter your email address', email:'Please enter a valid email address'}}"/>
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
</fieldset>
</form>
<!-- Custom message for "required" in metadata is overriden by a validate option -->
<form class="cmxform" id="commentForm3" method="post" action="">
<form class="cmxform" id="commentForm2" method="post" action="">
<fieldset>
<legend>Please enter your email address</legend>
<p>

<label for="cemail">E-Mail *</label>
<input id="cemail" name="email" class="{required:true, email:true, messages:{email:'Please enter a valid email address'}}"/>
<input id="cemail" name="email" data-rule-required="true" data-rule-email="true" data-msg-email="Please enter a valid email address" />
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
Expand All @@ -85,8 +70,5 @@ <h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-vali

<a href="index.html">Back to main page</a>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">_uacct = "UA-2623402-1";urchinTracker();</script>

</body>
</html>
2 changes: 1 addition & 1 deletion demo/index.html
Expand Up @@ -198,7 +198,7 @@ <h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-vali
<h3>Syntetic examples</h3>
<ul>
<li><a href="errorcontainer-demo.html">Error message containers in action</a></li>
<li><a href="custom-messages-metadata-demo.html">Custom Messages as Metadata</a></li>
<li><a href="custom-messages-data-demo.html">Custom Messages as Element Data</a></li>
<li><a href="radio-checkbox-select-demo.html">Radio and checkbox buttons and selects</a></li>
<li><a href="ajaxSubmit-intergration-demo.html">Integration with Form Plugin (AJAX submit)</a></li>
<li><a href="custom-methods-demo.html">Custom methods and message display.</a></li>
Expand Down
43 changes: 17 additions & 26 deletions jquery.validate.js
Expand Up @@ -148,9 +148,9 @@ $.extend($.fn, {
var data = $.validator.normalizeRules(
$.extend(
{},
$.validator.metadataRules(element),
$.validator.classRules(element),
$.validator.attributeRules(element),
$.validator.dataRules(element),
$.validator.staticRules(element)
), element);

Expand Down Expand Up @@ -571,16 +571,6 @@ $.extend($.validator, {
return true;
},

// return the custom message for the given element and validation method
// specified in the element's "messages" metadata
customMetaMessage: function(element, method) {
if (!$.metadata) {
return;
}
var meta = this.settings.meta ? $(element).metadata()[this.settings.meta] : $(element).metadata();
return meta && meta.messages && meta.messages[method];
},

// return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute
customDataMessage: function(element, method) {
Expand All @@ -607,7 +597,6 @@ $.extend($.validator, {
return this.findDefined(
this.customMessage( element.name, method ),
this.customDataMessage( element, method ),
this.customMetaMessage( element, method ),
// title is never undefined, so handle empty string as undefined
!this.settings.ignoreTitle && element.title || undefined,
$.validator.messages[method],
Expand Down Expand Up @@ -877,15 +866,16 @@ $.extend($.validator, {
return rules;
},

metadataRules: function(element) {
if (!$.metadata) {
return {};
dataRules: function(element) {
var method, value,
rules = {}, $element = $(element);
for (method in $.validator.methods) {
value = $element.data('rule-' + method.toLowerCase());
if (value !== undefined) {
rules[method] = value;
}
}

var meta = $.data(element.form, 'validator').settings.meta;
return meta ?
$(element).metadata()[meta] :
$(element).metadata();
return rules;
},

staticRules: function(element) {
Expand Down Expand Up @@ -935,8 +925,14 @@ $.extend($.validator, {
}
});
$.each(['rangelength', 'range'], function() {
var parts;
if (rules[this]) {
rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
if ($.isArray(rules[this])) {
rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
} else if (typeof rules[this] === 'string') {
parts = rules[this].split(/[\s,]+/);
rules[this] = [Number(parts[0]), Number(parts[1])];
}
}
});

Expand All @@ -954,11 +950,6 @@ $.extend($.validator, {
}
}

// To support custom messages in metadata ignore rule methods titled "messages"
if (rules.messages) {
delete rules.messages;
}

return rules;
},

Expand Down
122 changes: 0 additions & 122 deletions lib/jquery.metadata.js

This file was deleted.

0 comments on commit 6df33a8

Please sign in to comment.