Permalink
Browse files

Move the ‘Validation.prototype.renderErrorMessage’ method into a sepa…

…rate file
  • Loading branch information...
1 parent a87600c commit c790fd5c105b1518f992463c6def26ba5dee8842 @Baggz committed Mar 8, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/engines/json/renderErrorMessage.js
@@ -0,0 +1,31 @@
+/**
+ * RenderErrorMessage
+ *
+ * @param {string} attributeName
+ * @param {object} templateData
+ */
+Validation.prototype.renderErrorMessage = function(attributeName, templateData) {
+
+ // Gets an error message
+ var errorMessage = this.messages[attributeName];
+
+ // If the error message is a function
+ if (typeof errorMessage === 'function') {
+ return errorMessage(
+ templateData.property,
+ templateData.propertyValue,
+ templateData.attribute
+ );
+ }
+
+ // If the error message is a string
+ if (typeof errorMessage === 'string') {
+ each(templateData, function(key, value) {
+ errorMessage = errorMessage.replace(new RegExp('{{' + key + '}}', 'g'), value);
+ });
+ return errorMessage.replace(/\s+/g, ' ');
+ }
+
+ return '';
+
+};

0 comments on commit c790fd5

Please sign in to comment.