浏览代码

validate a value from a list of options

Marin Bezhanov 11 年之前
父节点
当前提交
d61f5418a3
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      src/js/validator/allowedValue.js

+ 15 - 0
src/js/validator/allowedValue.js

@@ -0,0 +1,15 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.allowedValue = {
+        /**
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field The jQuery object represents the field element
+         * @param {Object} options The validator options
+         * @returns {boolean}
+         */
+        validate: function(validator, $field, options) {
+			var value = $field.val();
+			var allowedValues = (options.allowedValues !== undefined) ? options.allowedValues : [];
+			return ($.inArray(value, allowedValues) > -1 ? true : false);
+        }
+    };
+}(window.jQuery));