Skip to main content

Bug Tracker

Side navigation

Ticket #2908: JqueryValidate-CustomMetaMessages-unix-again.patch
File JqueryValidate-CustomMetaMessages-unix-again.patch, 4.9 KB (added by DaneOConnor, May 22, 2008 02:57PM UTC)
Index: demo/custom-messages-metadata-demo.htm
===================================================================
--- demo/custom-messages-metadata-demo.htm	(revision 0)
+++ demo/custom-messages-metadata-demo.htm	(revision 0)
@@ -0,0 +1,85 @@
+
+
+
+
+jQuery validation plug-in - comment form example
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Please enter your email address +

+ + + +

+

+ +

+
+
+ +
+
+ Please enter your email address +

+ + + +

+

+ +

+
+
+ +
+
+ Please enter your email address +

+ + + +

+

+ +

+
+
+ + + + \ No newline at end of file Index: jquery.validate.js =================================================================== --- jquery.validate.js (revision 5616) +++ jquery.validate.js (working copy) @@ -122,15 +122,15 @@ } } - var data = jQuery.validator.normalizeRules( - jQuery.extend( - {}, + var ruleList = jQuery.extend({}, jQuery.validator.metadataRules(element), jQuery.validator.classRules(element), jQuery.validator.attributeRules(element), jQuery.validator.staticRules(element) - ), element); + ); + var data = jQuery.validator.normalizeRules(ruleList, element); + // make sure required is at front if (data.required) { var param = data.required; @@ -496,6 +496,20 @@ return true; }, + // return the custom message for the given element and validation method speicifed in the element's "messages" metadata + customMetaMessage: function(element, method) { + if (!jQuery.metadata) return undefined; + + var metaKey = jQuery.data(element.form, 'validator').settings.meta; + var meta = metaKey ? + jQuery(element).metadata()[metaKey] : + jQuery(element).metadata(); + + return meta.messages ? + meta.messages[method] : + undefined; + }, + // return the custom message for the given element name and validation method customMessage: function( name, method ) { var m = this.settings.messages[name]; @@ -516,6 +530,7 @@ defaultMessage: function( element, method) { return this.findDefined( this.customMessage( element.name, method ), + this.customMetaMessage( element, method ), // title is never undefined, so handle empty string as undefined element.title || undefined, jQuery.validator.messages[method], @@ -831,6 +846,11 @@ } } + // To support custom messages in metadata ignore rule methods titled "messages" + if (rules.messages) { + delete rules.messages + } + return rules; },

Download in other formats:

Original Format