From 5e99dd4e54b8544415ba611eadefee4e793c48a8 Mon Sep 17 00:00:00 2001 From: jk Date: Sat, 12 Dec 2015 12:28:06 +0100 Subject: [PATCH] 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'); }); --- js/foundation.abide.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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'); } }; /** -- 2.47.2