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

Add optional submitter argument to FormData constructor #366

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions xhr.bs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Translation: ja https://triple-underscore.github.io/XHR-ja.html
Translate IDs: enumdef-xmlhttprequestresponsetype xmlhttprequestresponsetype,dictdef-progresseventinit progresseventinit,typedefdef-formdataentryvalue formdataentryvalue
</pre>

<!-- Temporary: https://github.com/w3c/webdriver-bidi/issues/358 -->
<pre class=link-defaults>
spec:webdriver-bidi; type:dfn; text:event
</pre>

<pre class=anchors>
urlPrefix: https://w3c.github.io/DOM-Parsing/; spec: dom-parsing
type: dfn; text: fragment serializing algorithm; url: dfn-fragment-serializing-algorithm
Expand Down Expand Up @@ -1609,7 +1614,7 @@ typedef (File or USVString) FormDataEntryValue;

[Exposed=(Window,Worker)]
interface FormData {
constructor(optional HTMLFormElement form);
constructor(optional HTMLFormElement form, optional HTMLElement? submitter = null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a nit after all. Is there a good reason to allow null here? Or would requiring undefined by fine? If there's no use case for passing null we should not allow it and change the language below from "is non-null" to "is given".

(And then have an additional test that null throws.)

Copy link
Member Author

@jenseng jenseng Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference here, mainly I was making it consistent with HTMLFormElement.requestSubmit which allows a null submitter.

But I agree that allowing a null submitter but not a null form is inconsistent, so 🤷‍♂️😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's fairly compelling I suppose, although I don't remember the rationale for that one. 😅

Let's leave this as-is then unless @domenic cares more strongly than I do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible it was an oversight, as you had a similar suggestion when requestSubmit was proposed and afaict it was never directly addressed

Copy link
Member Author

@jenseng jenseng Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah here's a good justification for requestSubmit accepting null: whatwg/html#3195 (comment)

Similarly this could be useful for the FormData constructor, e.g. SubmitEvent.submitter could be null, and it would be nice to avoid null checks:

myForm.addEventListener("submit", (e) => {
  e.preventDefault();
  const formData = new FormData(e.target, e.submitter);
  // ...
});


undefined append(USVString name, USVString value);
undefined append(USVString name, Blob blobValue, optional USVString filename);
Expand All @@ -1635,16 +1640,27 @@ interface FormData {
moved to the HTML Standard. [[HTML]]

<p>The
<dfn id=dom-formdata constructor for=FormData lt="FormData(form)"><code>new FormData(<var>form</var>)</code></dfn>
<dfn id=dom-formdata constructor for=FormData lt="FormData(form)"><code>new FormData(<var>form</var>, <var>submitter</var>)</code></dfn>
constructor steps are:

<ol>
<li>
<p>If <var>form</var> is given, then:

<ol>
<li>
<p>If <var>submitter</var> is non-null, then:

<ol>
<li><p>If <var>submitter</var> is not a <a>submit button</a>, then <a>throw</a> a
{{TypeError}}.

<li><p>If <var>submitter</var>'s <a>form owner</a> is not <var>form</var>, then <a>throw</a> a
"{{NotFoundError!!exception}}" {{DOMException}}.
</ol>

<li><p>Let <var>list</var> be the result of <a>constructing the entry list</a> for
<var>form</var>.
<var>form</var> and <var>submitter</var>.

<li><p>If <var>list</var> is null, then <a>throw</a> an "{{InvalidStateError!!exception}}"
{{DOMException}}.
Expand Down