Browse Source

Readd hexColor validator as a stand-alone validator, to not break backwards compat

Emil Rømer Christensen 11 years ago
parent
commit
c184993bbb
1 changed files with 24 additions and 0 deletions
  1. 24 0
      src/js/validator/hexColor.js

+ 24 - 0
src/js/validator/hexColor.js

@@ -0,0 +1,24 @@
+(function($) {
+    $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
+        'default': 'Please enter a valid hex color'
+    });
+
+    $.fn.bootstrapValidator.validators.hexColor = {
+        enableByHtml5: function($field) {
+            return ('color' === $field.attr('type'));
+        },
+
+        /**
+         * Return true if the input value is a valid hex color
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Can consist of the following keys:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            return $.fn.bootstrapValidator.validators.color._hexColor(validator, $field, options);
+        }
+    };
+}(window.jQuery));