From: jk Date: Sat, 12 Dec 2015 11:28:06 +0000 (+0100) Subject: fires/bind formValid.fndtn.abide,formInvalid.fndtn.abide default bind submit() to... X-Git-Tag: v6.1.0~4^2^2~17^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7481%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git fires/bind formValid.fndtn.abide,formInvalid.fndtn.abide default bind submit() to this event can be off by $('[data-abide]').off('formValid').on('formValid.fndtn.abide', function() { console.log('do something'); }); --- diff --git a/js/foundation.abide.js b/js/foundation.abide.js index e4a601a75..b7f9b22dd 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -95,6 +95,9 @@ e.preventDefault(); self.validateForm(self.$element); }) + .on('formValid.fndtn.abide',function(e){ + self.$element[0].submit(); + }) .find('input, textarea, select') .off('.abide') .on('blur.fndtn.abide change.fndtn.abide', function (e) { @@ -275,8 +278,10 @@ } }; /** - * Goes through a form and if there are any invalid inputs, it will display the form error element - * @param {Object} element - jQuery object to validate, should be a form HTML element + * Goes through a form and if there are any invalid inputs, it will display the form error element. If valid formValid fired. By default form.submit(); is bind to formValid. You can override formValid by $('[data-abide]').off('formValid').on('formValid.fndtn.abide',function(){...}); + * @param {Object} element - jQuery object to validate, should be a form HTML element. + * @fires Abide#formInvalid + * @fires Abide#formValid */ Abide.prototype.validateForm = function($form) { var self = this, @@ -292,10 +297,11 @@ // what are all the things that can go wrong with a form? if ($form.find('.form-error.is-visible').length || $form.find('.is-invalid-label').length) { $form.find('[data-abide-error]').css('display', 'block'); + $form.trigger('formInvalid.fndtn.abide'); } else { $form.find('[data-abide-error]').css('display', 'none'); - $form[0].submit(); + $form.trigger('formValid.fndtn.abide'); } }; /**