Browse Source

update fix check ajax twice when submit

khangvu 12 years ago
parent
commit
d88da05542

+ 6 - 4
dist/js/bootstrapValidator.js

@@ -47,7 +47,9 @@
                     that.formSubmited = true;
                     if (that.options.fields) {
                         for (var field in that.options.fields) {
-                            that.validateField(field);
+                            if(that.numPendingRequests > 0){
+                                that.validateField(field);
+                            }
                         }
                         if (!that.isValid()) {
                             e.preventDefault();
@@ -169,6 +171,7 @@
             }
 
             if (this.xhrRequests[field][validatorName]) {
+                this.numPendingRequests--;
                 this.xhrRequests[field][validatorName].abort();
             }
             this.xhrRequests[field][validatorName] = xhr;
@@ -396,6 +399,7 @@
          * @returns {string}
          */
         validate: function(validator, $field, options) {
+
             var value = $field.val(), name = $field.attr('name');
             var data = options.data;
             if (data == null) {
@@ -409,10 +413,8 @@
                 data: data
             }).success(function(response) {
                 var isValid =  response.valid === true || response.valid === 'true';
-                if (!isValid) {
-                    validator.showError($field, 'remote');
-                }
                 validator.completeRequest($field, 'remote', isValid);
+                console.log('success',validator.numPendingRequests);
             });
             validator.startRequest($field, 'remote', xhr);
 

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


+ 4 - 1
src/js/bootstrapValidator.js

@@ -47,7 +47,9 @@
                     that.formSubmited = true;
                     if (that.options.fields) {
                         for (var field in that.options.fields) {
-                            that.validateField(field);
+                            if(that.numPendingRequests > 0){
+                                that.validateField(field);
+                            }
                         }
                         if (!that.isValid()) {
                             e.preventDefault();
@@ -169,6 +171,7 @@
             }
 
             if (this.xhrRequests[field][validatorName]) {
+                this.numPendingRequests--;
                 this.xhrRequests[field][validatorName].abort();
             }
             this.xhrRequests[field][validatorName] = xhr;

+ 1 - 2
src/js/validator/remote.js

@@ -15,6 +15,7 @@
          * @returns {string}
          */
         validate: function(validator, $field, options) {
+
             var value = $field.val(), name = $field.attr('name');
             var data = options.data;
             if (data == null) {
@@ -29,8 +30,6 @@
             }).success(function(response) {
                 var isValid =  response.valid === true || response.valid === 'true';
                 validator.completeRequest($field, 'remote', isValid);
-            }).error(function(response) {
-                validator.completeRequest($field, 'remote', false);
             });
             validator.startRequest($field, 'remote', xhr);