@robmarr/intercept-form-submits
v0.5.0 browser forms
Intercept Form Submits
This module is mainly to intercept applicable form submits for a single-page app router. The options are geared toward intercepting internal links that should change the page state in some way.
Install
npm i intercept-form-submits
Usage
var interceptSubmits = require('intercept-form-submits');
interceptSubmits(function(e, el) {
// Change the page state here
// `e` is the event object
// `el` is the submitted form, which might be different from `e.target`
});
A more advanced usage is to pass options and an optional element:
interceptSubmits(document.querySelector('.my-el'), {
//
// Leave all these as defaults:
//
// dialog: true
// get: true
// post: true
// mailTo: true
// sameOrigin: true
// target: true
// Intercept all submits, even ones that are not same origin
sameOrigin: false
}, function(e, el) {
// Change the page state here
});
Thanks Wes Todd for Intercept Link Clicks on which this module is heavily based.
npm i @robmarr/intercept-form-submits
Metadata
- ISC
- Whatever
- Robin Marr
- released 7/31/2020