ソースを参照

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));