Skip to content

Commit

Permalink
Event-based form participation
Browse files Browse the repository at this point in the history
- Add formdata event and FormDataEvent interface
- Fire it in "constructing the entry list" algorithm
- Introduce "constructing entry list" flag of a form element to avoid recursive submission.

Tests: web-platform-tests/wpt#14637.

Change to XMLHttpRequest: whatwg/xhr#231.

This fixes a part of WICG/webcomponents#187.
  • Loading branch information
tkent-google authored and annevk committed Jan 8, 2019
1 parent 5e370be commit 1375c0c
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3411,6 +3411,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x="dom-ProgressEvent-loaded" data-x-href="https://xhr.spec.whatwg.org/#dom-progressevent-loaded"><code>ProgressEvent.loaded</code></dfn> attribute</li>
<li><dfn data-x="dom-ProgressEvent-total" data-x-href="https://xhr.spec.whatwg.org/#dom-progressevent-total"><code>ProgressEvent.total</code></dfn> attribute</li>
<li><dfn data-x="fire a progress event" data-x-href="https://xhr.spec.whatwg.org/#concept-event-fire-progress">Fire a progress event named <var>e</var></dfn></li>
<li><dfn data-x-href="https://xhr.spec.whatwg.org/#formdata"><code>FormData</code></dfn>
interface</li>
<li>The concept of <dfn data-x="formdata-entry" data-x-href="https://xhr.spec.whatwg.org/#concept-formdata-entry">entry</dfn></li>
<li><dfn data-x-href="https://xhr.spec.whatwg.org/#create-an-entry">create an entry</dfn></li>
</ul>
Expand Down Expand Up @@ -55777,6 +55779,9 @@ fur

<h5>Form submission algorithm</h5>

<p>Each <code>form</code> element has a <dfn>constructing entry list</dfn> boolean, initially
false.</p>

<p>When a <code>form</code> element <var>form</var> is <dfn
data-x="concept-form-submit">submitted</dfn> from an element <var>submitter</var>
(typically a button), optionally with a <var>submitted from <code
Expand All @@ -55786,6 +55791,8 @@ fur
<ol>
<li><p>If <var>form</var> <span>cannot navigate</span>, then return.</p></li>

<li><p>If <var>form</var>'s <span>constructing entry list</span> is true, then return.</p></li>

<li><p>Let <var>form document</var> be <var>form</var>'s <span>node document</span>.</p></li>

<li id="sandboxSubmitBlocked"><p>If <var>form document</var>'s <span>active sandboxing flag
Expand Down Expand Up @@ -55835,6 +55842,14 @@ fur
<li><p>Let <var>entry list</var> be the result of <span>constructing the entry list</span> with
<var>form</var>, <var>submitter</var>, and <var>encoding</var>.</p></li>

<li>
<p>If <var>form</var> <span>cannot navigate</span>, then return.</p>

<p class="note"><span>Cannot navigate</span> is run again as dispatching the <code
data-x="event-formdata">formdata</code> event in <span>constructing the entry list</span>
could have changed the outcome.</p>
</li>

<li><p>Let <var>action</var> be the <var>submitter</var> element's <span
data-x="concept-fs-action">action</span>.</p></li>

Expand Down Expand Up @@ -56149,6 +56164,11 @@ fur
follows. If not specified otherwise, <var>submitter</var> is null.</p>

<ol>
<li><p>If <var>form</var>'s <span>constructing entry list</span> is true, then return
null.</p></li>

<li><p>Set <var>form</var>'s <span>constructing entry list</span> to true.</p></li>

<li><p>Let <var>controls</var> be a list of all the <span
data-x="category-submit">submittable elements</span> whose <span>form owner</span> is <var>form</var>, in <span>tree order</span>.</p></li>

Expand Down Expand Up @@ -56338,6 +56358,16 @@ fur
</ol>
</li>

<li><p>Let <var>form data</var> be a new <code>FormData</code> object associated with
<var>entry list</var>.</p></li>

<li><p><span data-x="concept-event-fire">Fire an event</span> named
<code data-x="event-formdata">formdata</code> at <var>form</var> using
<code>FormDataEvent</code>, with the <code data-x="dom-FormDataEvent-formData">formData</code>
attribute initialized to <var>form data</var>.</p></li>

<li><p>Set <var>form</var>'s <span>constructing entry list</span> to false.</p></li>

<li><p>Return <var>entry list</var>.</p></li>
</ol>

Expand Down Expand Up @@ -56535,10 +56565,38 @@ fur
not reliably interpretable by computer, as the format is ambiguous (for example, there is no way
to distinguish a literal newline in a value from the newline at the end of the value).</p>

<h5>The <code>FormDataEvent</code> interface</h5>

<pre><code class="idl" data-x="">[Exposed=Window,
Constructor(DOMString type, optional FormDataEventInit eventInitDict)]
interface <dfn>FormDataEvent</dfn> : <span>Event</span> {
readonly attribute <span>FormData</span> <span data-x="dom-FormDataEvent-formData">formData</span>;
};

dictionary <dfn>FormDataEventInit</dfn> : <span>EventInit</span> {
required <span>FormData</span> formData;
};</code></pre>

<dl class="domintro">

<dt><var>event</var> . <code data-x="dom-FormDataEvent-formData">formData</code></dt>

<dd>

<p>Returns a <code>FormData</code> object representing names and values of elements associated
to the target <code>form</code>. Operations on the <code>FormData</code> object will affect
form data to be submitted.</p>

</dd>

</dl>

<div w-nodev>

<p>The <dfn><code data-x="dom-FormDataEvent-formData">formData</code></dfn> attribute must return the value it was
initialized to. It represents a <code>FormData</code> object associated to the entry list that is <span
data-x="constructing the entry list">constructed</span> when the <code>form</code> is submitted.</p>

<h4>Resetting a form</h4>

<p>When a <code>form</code> element <var>form</var> is <dfn
Expand Down Expand Up @@ -90863,6 +90921,7 @@ typedef <span>OnBeforeUnloadEventHandlerNonNull</span>? <dfn>OnBeforeUnloadEvent
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-ondurationchange">ondurationchange</code></dfn> <td> <code data-x="event-media-durationchange">durationchange</code>
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-onemptied">onemptied</code></dfn> <td> <code data-x="event-media-emptied">emptied</code>
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-onended">onended</code></dfn> <td> <code data-x="event-media-ended">ended</code>
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-onformdata">onformdata</code></dfn> <td> <code data-x="event-formdata">formdata</code>
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-oninput">oninput</code></dfn> <td> <code data-x="event-input">input</code>
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-oninvalid">oninvalid</code></dfn> <td> <code data-x="event-invalid">invalid</code>
<tr><td><dfn data-export="" data-dfn-type="attribute" data-dfn-for="HTMLElement,Document,Window,GlobalEventHandlers"><code data-x="handler-onkeydown">onkeydown</code></dfn> <td> <code data-x="event-keydown">keydown</code> <!-- widely used -->
Expand Down Expand Up @@ -91043,6 +91102,7 @@ typedef <span>OnBeforeUnloadEventHandlerNonNull</span>? <dfn>OnBeforeUnloadEvent
attribute <span>EventHandler</span> <span data-x="handler-onended">onended</span>;
attribute <span>OnErrorEventHandler</span> <span data-x="handler-onerror">onerror</span>;
attribute <span>EventHandler</span> <span data-x="handler-onfocus">onfocus</span>;
attribute <span>EventHandler</span> <span data-x="handler-onformdata">onformdata</span>;
attribute <span>EventHandler</span> <span data-x="handler-oninput">oninput</span>;
attribute <span>EventHandler</span> <span data-x="handler-oninvalid">oninvalid</span>;
attribute <span>EventHandler</span> <span data-x="handler-onkeydown">onkeydown</span>;
Expand Down Expand Up @@ -119996,6 +120056,12 @@ interface <dfn>External</dfn> {
<td> <code data-x="event-focus">focus</code> event handler
<td> <span data-x="event handler content attributes">Event handler content attribute</span>

<tr>
<th id="ix-handler-onformdata"> <code data-x="">onformdata</code>
<td> <span data-x="handler-onformdata">HTML elements</span>
<td> <code data-x="event-formdata">formdata</code> event handler
<td> <span data-x="event handler content attributes">Event handler content attribute</span>

<tr>
<th id="ix-handler-window-onhashchange"> <code data-x="">onhashchange</code>
<td> <code data-x="handler-window-onhashchange">body</code>
Expand Down Expand Up @@ -120889,6 +120955,12 @@ INSERT INTERFACES HERE
<td> <code>Window</code>, elements
<td> Fired at nodes <span data-x="gains focus">gaining focus</span>

<tr> <!-- formdata -->
<td> <dfn data-dfn-type="event" data-dfn-for="HTMLElement" data-export=""><code data-x="event-formdata">formdata</code></dfn>
<td> <code>FormDataEvent</code>
<td> <code>form</code> elements
<td> Fired at a <code>form</code> element when it is <span>constructing the entry list</span>

<tr> <!-- hashchange -->
<td> <dfn data-dfn-type="event" data-dfn-for="Window" data-export=""><code data-x="event-hashchange">hashchange</code></dfn>
<td> <code>HashChangeEvent</code>
Expand Down

0 comments on commit 1375c0c

Please sign in to comment.