浏览代码

Refactor the way custom messages are handled

Emil Rømer Christensen 11 年之前
父节点
当前提交
ed794f62d5
共有 1 个文件被更改,包括 9 次插入6 次删除
  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) {