TIL form elements have a formdata event
If you're using FormData from a form, you can stop listening for submit events!
Whoa, this is neat. Check out the FormDataEvent
on MDN!
You donβt need to construct an instance of FormData
if instead of listening for submit
events you listen for formdata
events!
// modified from MDN docs for brevity
formElem.addEventListener(
"formdata",
(e) => {
const formData = e.formData;
console.log(
"formdata fired",
formData,
);
},
);
It even has great browser support!