Browse Source

Ensured debounce works on multiple remote validators

Adam Barker 11 years ago
parent
commit
2c52607d38
4 changed files with 12 additions and 11 deletions
  1. 3 2
      demo/remote.html
  2. 4 4
      dist/js/bootstrapValidator.js
  3. 1 1
      dist/js/bootstrapValidator.min.js
  4. 4 4
      src/js/validator/remote.js

+ 3 - 2
demo/remote.html

@@ -111,7 +111,7 @@ $(document).ready(function() {
                     remote: {
                         url: 'remote.php',
                         message: 'The username is not available',
-                        debounceDelay: 800
+                        debounceDelay: 1000
                     },
                     different: {
                         field: 'password',
@@ -129,7 +129,8 @@ $(document).ready(function() {
                     },
                     remote: {
                         url: 'remote.php',
-                        message: 'The email is not available'
+                        message: 'The email is not available',
+                        debounceDelay: 1000
                     }
                 }
             },

+ 4 - 4
dist/js/bootstrapValidator.js

@@ -3117,7 +3117,7 @@
             debounceDelay: 'debounceDelay'
         },
 
-        _timer: null,
+        _timer: [],
 
         /**
          * Request a remote server to check the input value
@@ -3155,10 +3155,10 @@
             var dfd = new $.Deferred();
 
             if (options.debounceDelay) {
-                if(this._timer) {
-                    clearTimeout(this._timer);
+                if(this._timer[name]) {
+                    clearTimeout(this._timer[name]);
                 }
-                this._timer = setTimeout(runCallback, options.debounceDelay);
+                this._timer[name] = setTimeout(runCallback, options.debounceDelay);
                 return dfd;
             }
             else

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


+ 4 - 4
src/js/validator/remote.js

@@ -7,7 +7,7 @@
             debounceDelay: 'debounceDelay'
         },
 
-        _timer: null,
+        _timer: [],
 
         /**
          * Request a remote server to check the input value
@@ -45,10 +45,10 @@
             var dfd = new $.Deferred();
 
             if (options.debounceDelay) {
-                if(this._timer) {
-                    clearTimeout(this._timer);
+                if(this._timer[name]) {
+                    clearTimeout(this._timer[name]);
                 }
-                this._timer = setTimeout(runCallback, options.debounceDelay);
+                this._timer[name] = setTimeout(runCallback, options.debounceDelay);
                 return dfd;
             }
             else