]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Fixed an issue where the validation was triggered multiple times. 6406/head
authorBart Riemens <briemens@crafity.com>
Fri, 20 Mar 2015 09:26:37 +0000 (10:26 +0100)
committerBart Riemens <briemens@crafity.com>
Fri, 20 Mar 2015 09:26:37 +0000 (10:26 +0100)
Used the timeout mechanisme to detect duplicate validation requests triggered in a short period of time.
Opinion: The Foundation abide validation code is very crappy and poorly written.

js/foundation/foundation.abide.js

index 97958a4f76fe9c4b0b8b03e2a857f61f6e754568..45e8361bc4b945e4f7b7d5a7bf69c47caef1be53 100644 (file)
 
       this.invalid_attr = this.add_namespace('data-invalid');
 
+      function validate(originalSelf, e) {
+        clearTimeout(self.timer);
+        self.timer = setTimeout(function () {
+          self.validate([originalSelf], e);
+        }.bind(originalSelf), settings.timeout);
+      }
+
+
       form
         .off('.abide')
         .on('submit.fndtn.abide', function (e) {
             // old settings fallback
             // will be deprecated with F6 release
             if (settings.validate_on_blur && settings.validate_on_blur === true) {
-              clearTimeout(self.timer);
-              self.timer = setTimeout(function () {
-                self.validate([this], e);
-              }.bind(this), settings.timeout);
+              validate(this, e);
             }
             // new settings combining validate options into one setting
             if (settings.validate_on === 'change') {
-              self.validate([this], e);
+              validate(this, e);
             }
           })
           .on('keydown.fndtn.abide', function (e) {
             // old settings fallback
             // will be deprecated with F6 release
             if (settings.live_validate && settings.live_validate === true && e.which != 9) {
-              clearTimeout(self.timer);
-              self.timer = setTimeout(function () {
-                self.validate([this], e);
-              }.bind(this), settings.timeout);
+              validate(this, e);
             }
             // new settings combining validate options into one setting
             if (settings.validate_on === 'tab' && e.which === 9) {
-              self.validate([this], e);
+              validate(this, e);
             }
             else if (settings.validate_on === 'change') {
-              self.validate([this], e);
+              validate(this, e);
             }
           })
           .on('focus', function (e) {