Browse Source

Refactor the way custom messages are handled

Emil Rømer Christensen 11 years ago
parent
commit
ed794f62d5
1 changed files with 9 additions and 6 deletions
  1. 9 6
      src/js/validator/color.js

+ 9 - 6
src/js/validator/color.js

@@ -22,20 +22,23 @@
                 return true;
             }
 
-            var method;
+            var method, type;
             var defaultTypes = ['hex', 'rgb', 'rgba', 'hsl', 'hsla', 'keyword'];
             var useCustomTypes = (options.hasOwnProperty('type') && options.type instanceof Array);
             var types = useCustomTypes ? options.type : defaultTypes;
             var isValid = false;
+            var formatedMessage = $.fn.bootstrapValidator.helpers.format(options.message || (useCustomTypes ? $.fn.bootstrapValidator.i18n.color.type : $.fn.bootstrapValidator.i18n.color.default), types.join(", "));
 
-            for (var i = 0; i<types.length; i++) {
-                var type = types[i];
-                message = useCustomTypes ? $.fn.bootstrapValidator.i18n.color.type : $.fn.bootstrapValidator.i18n.color.default;
-                method = ['_', type.toLowerCase()].join('');
+            for (var i = 0; i < types.length; i++) {
+                type = types[i];
+                method = '_' + type.toLowerCase();
                 isValid = isValid || this[method](value);
             }
 
-            return isValid || { valid: false, message: message };
+            return isValid || {
+                valid: false,
+                message: formatedMessage
+            };
         },
 
         _hex: function(value) {