From: Bart Riemens Date: Fri, 20 Mar 2015 09:26:37 +0000 (+0100) Subject: Fixed an issue where the validation was triggered multiple times. X-Git-Tag: v5.5.2~55^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6406%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Fixed an issue where the validation was triggered multiple times. 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. --- diff --git a/js/foundation/foundation.abide.js b/js/foundation/foundation.abide.js index 97958a4f7..45e8361bc 100644 --- a/js/foundation/foundation.abide.js +++ b/js/foundation/foundation.abide.js @@ -70,6 +70,14 @@ 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) { @@ -90,31 +98,25 @@ // 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) {