-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Introduction
When adding a submit handler to a form, one often wants to get the data that was submitted:
form.addEventListener('submit', e => {
const data = new FormData(e.target);
});
But this contains a subtle bug: it's missing the data from the submitter element. The correct way to do it is using the submitter argument to FormData: new FormData(e.target, e.submitter).
It would be nice if, instead, a field with the submitted FormData already existed on SubmitEvent. This would simplify the manual, error-prone creation of FormData to e.submittedFormData.
As a bonus, this is easily shimmed.
Use Cases (Recommended)
Getting the submitted data from a submitted form.
Goals (Optional)
Add a new field to SubmitEvent that contains the submitted form data. The name doesn't matter, I just suggested submittedFormData arbitrarily, but it could be as simple as data or formData if that works.
Proposed Solution
Ibid.
Alternate Approaches (Optional)
This adds no new functionality, but makes code that gets submitted data cleaner and less error prone. The intention is obvious (e.submittedFormData == "get the submitted form data") rather than containing logic (manually creating a FormData, passing all the necessary arguments).
There is a related proposal (#207), but rather than adding a field on SubmitEvent, it adds a method sendWith that takes a callback which accepts a "submission" object that has the submitted data. The approach here is simpler for the stated use case.
Privacy & Security Considerations
No considerable privacy or security concerns are expected, but we welcome community feedback.