]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fires/bind formValid.fndtn.abide,formInvalid.fndtn.abide default bind submit() to... 7481/head
authorjk <j.koehler@modulingo.de>
Sat, 12 Dec 2015 11:28:06 +0000 (12:28 +0100)
committerjk <j.koehler@modulingo.de>
Sat, 12 Dec 2015 11:28:06 +0000 (12:28 +0100)
can be off by
$('[data-abide]').off('formValid').on('formValid.fndtn.abide', function() {
  console.log('do something');
});

js/foundation.abide.js

index e4a601a75418cc325a6cc5ef828e60867207fd5e..b7f9b22dd3f9dde48d83658fdc1e07818e73770e 100644 (file)
@@ -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) {
     }
   };
   /**
-   * 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,
     // 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');
     }
   };
   /**