浏览代码

Update different validator

Changed different validator to be able to check multiple fields for cases where there are more than two to compare.
Mike Podruchny 11 年之前
父节点
当前提交
868e770c80
共有 1 个文件被更改,包括 12 次插入9 次删除
  1. 12 9
      src/js/validator/different.js

+ 12 - 9
src/js/validator/different.js

@@ -25,17 +25,20 @@
                 return true;
             }
 
-            var compareWith = validator.getFieldElements(options.field);
-            if (compareWith === null) {
-                return true;
-            }
+            var spl = options.field.split(',');
+            var isValid = true;
+            for (i = 0; i < spl.length; i++) {
+                var compareWith = validator.getFieldElements(spl[i]);
+                if (compareWith == null) {
+                    continue;
+                }
 
-            if (value !== compareWith.val()) {
-                validator.updateStatus(options.field, validator.STATUS_VALID, 'different');
-                return true;
-            } else {
-                return false;
+                if (value == compareWith.val())
+                    isValid = false;
+                else
+                    validator.updateStatus(spl[i], validator.STATUS_VALID, 'different');
             }
+            return isValid;
         }
     };
 }(window.jQuery));