Browse Source

#783: Improve behaviour of the different validator

Phuoc Nguyen 11 years ago
parent
commit
5d5c4864ff

+ 1 - 0
CHANGELOG.md

@@ -22,6 +22,7 @@ __Improvements__
 * [#734](https://github.com/nghuuphuoc/bootstrapvalidator/pull/734): The [uri](http://bootstrapvalidator.com/validators/uri/) validator adds support for custom protocol, thanks to [@bcamarneiro](https://github.com/bcamarneiro)
 * [#737](https://github.com/nghuuphuoc/bootstrapvalidator/issues/737): Support VAT number without prefixing by country code
 * [#754](https://github.com/nghuuphuoc/bootstrapvalidator/issues/754): Support latest Bootstrap when using tooltip/popover to show the message
+* [#783](https://github.com/nghuuphuoc/bootstrapvalidator/issues/783): Improve behaviour of the [different](http://bootstrapvalidator.com/validators/different/) validator
 
 __Bug Fixes__
 * [#611](https://github.com/nghuuphuoc/bootstrapvalidator/issues/611), [#703](https://github.com/nghuuphuoc/bootstrapvalidator/issues/703): Tabs get red even form is valid

+ 1 - 1
demo/index.html

@@ -240,7 +240,7 @@ $(document).ready(function() {
                         message: 'The username is not available'
                     },
                     different: {
-                        field: 'password',
+                        field: 'password,confirmPassword',
                         message: 'The username and password cannot be the same as each other'
                     }
                 }

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.2-dev, built on 2014-09-02 11:09:14 PM
+ * @version     v0.5.2-dev, built on 2014-09-05 2:39:38 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 5 - 4
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.2-dev, built on 2014-09-02 11:09:14 PM
+ * @version     v0.5.2-dev, built on 2014-09-05 2:39:38 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -2570,10 +2570,11 @@
                     continue;
                 }
 
-                if (value === compareWith.val()) {
+                var compareValue = compareWith.val();
+                if (value === compareValue) {
                     isValid = false;
-                } else {
-                    validator.updateStatus(fields[i], validator.STATUS_VALID, 'different');
+                } else if (compareValue !== '') {
+                    validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
                 }
             }
 

File diff suppressed because it is too large
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 4 - 3
src/js/validator/different.js

@@ -34,10 +34,11 @@
                     continue;
                 }
 
-                if (value === compareWith.val()) {
+                var compareValue = compareWith.val();
+                if (value === compareValue) {
                     isValid = false;
-                } else {
-                    validator.updateStatus(fields[i], validator.STATUS_VALID, 'different');
+                } else if (compareValue !== '') {
+                    validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
                 }
             }