Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormData: Add ability to specify submitter in addition to <form> #262

Closed
tkent-google opened this issue Nov 1, 2019 · 2 comments · Fixed by #366
Closed

FormData: Add ability to specify submitter in addition to <form> #262

tkent-google opened this issue Nov 1, 2019 · 2 comments · Fixed by #366
Labels
addition/proposal New features or enhancements needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan topic: formdata

Comments

@tkent-google
Copy link
Contributor

Context: whatwg/html#3195
Context: #202

FormData should have ability to add an entry for a submitter button when it appends entries for a <form>.

We have multiple options of how to specify submitter. See five comments since whatwg/html#3195 (comment)


A) constructor(optional (HTMLFormElement or record<USVString, FormDataEntryValue>) formOrMap, optional HTMLElement? submitter = null)
Idiomatic.

B) constructor(optional (HTMLElement or record<...>) formOrSubmitterOrMap)
HTMLElement represents a form or a submitter.

C) constructor(optional (HTMLFormElement or FormDataInit) formOrDict)

dictionary FormDataInit {
 HTMLFormElement form;
 HTMLElement? submitter;
 record<...> map;
}

The content of the dictionary is idiomatic.
Need to wrap a record with a dictionary.
Extensible. It's easy to add new members to the dictionary in the future.

D) constructor(optional (HTMLFormElement or FormDataInit or URLSearchParams) init)

dictionary FormDataInit {
  required HTMLFormElement form;
  HTMLElement? submitter = null;
}

FormData doesn't support record<> directly. Developers have to write new FormData(new URLSearchParams(map)).

E) constructor(optional HTMLFormElement form, optional HTMLElement? submitter = null)
FormData append(record<USVString, FormDataEntryValue> map);
Developers have to write new FormData().append(map).

F) (no changes on the constructor)

FormData append(HTMLFormElement form, optional HTMLElement? submitter = null);
FormData append(record<USVString, FormDataEntryValue> map);

Developers have to write let fd = new FormData().append(form, submitter); if they want to collect entries including an entry for the submitter.

@annevk
Copy link
Member

annevk commented Nov 1, 2019

From that discussion, I think there's agreement on adding a second optional argument to address the use cases from @muan et al. If we were to extend FormData further to support similar initialization to URLSearchParams we can revisit A vs E vs overloading at that point.

@annevk annevk added addition/proposal New features or enhancements needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan labels Feb 4, 2020
@whatwg whatwg deleted a comment from Bf916 Mar 2, 2022
@jenseng
Copy link
Member

jenseng commented Oct 10, 2022

Is it worth also providing a way to pass in the selected x/y coordinate when the submitter is an Image Button? That would allow for full parity with the form submission algorithm (though it would require the developer to capture the coordinate, e.g. via click handler) edit 2013-01-11 after reading the various specs, it seems like this should be handled implicitly as below

Or alternatively this could be implicitly handled by implementations (i.e. the coordinate would be recorded when the user selects it, and later used when constructing the data set, as is the case with a normal form submission)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan topic: formdata
Development

Successfully merging a pull request may close this issue.

3 participants