Browse Source

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 years ago
parent
commit
868e770c80
1 changed files with 12 additions and 9 deletions
  1. 12 9
      src/js/validator/different.js

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

@@ -25,17 +25,20 @@
                 return true;
                 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));
 }(window.jQuery));