Form actions

Submit and reset a form inside a component

Outside submit and reset buttons target a form inside the component.

Try: Submit with Email empty, Save draft to skip validation, then edit a field and Reset.

Inside the shadow root

This example requires a browser that parses declarative shadow DOM.

Outside the shadow root

Controls stay disabled until the form’s handlers are ready.

Actual native button.form getters

Waiting for setup…

Submission data

No submission yet. The submit handler cancels navigation and reads native FormData synchronously.

No submit event yet.

Native form events

  1. No events yet.

Reset restores the name, an empty email, a weekly digest, and the checked updates box.

Behavior & limits

Submit validates; Save draft skips validation and includes intent=draft; Reset restores defaults. The demo cancels navigation and reads FormData synchronously, so no data leaves the page.

The fallback routes actions without associating external data controls or changing native .form getters. Its temporary internal submitter carries the outside button’s name, value and form overrides; submitter identity and event paths differ from native Reference Target.

Code sample

Keep data controls inside the form; install submit handlers before enabling the buttons.

<rt-profile-form id="profile-form" data-reference-target="inner-form">
  <template shadowrootmode="open" shadowrootreferencetarget="inner-form">
    <form id="inner-form">
      <label for="email">Email</label>
      <input id="email" type="email" name="email" required>
    </form>
  </template>
</rt-profile-form>
<button id="submit-profile" type="submit" form="profile-form"
    name="intent" value="submit" disabled>Submit</button>
<button id="save-draft" type="submit" form="profile-form"
    name="intent" value="draft" formnovalidate disabled>Save draft</button>
<button id="reset-profile" type="reset" form="profile-form" disabled>Reset</button>
const form = document.getElementById('profile-form')
  .shadowRoot.getElementById('inner-form');

form.addEventListener('submit', event => {
  event.preventDefault();
  // Read synchronously: a fallback submitter exists only during dispatch.
  const data = new FormData(form, event.submitter);
  submitProfile(data); // Application-owned validation and transport.
});
for (const id of ['submit-profile', 'save-draft', 'reset-profile']) {
  document.getElementById(id).disabled = false;
}

Functional JavaScript sizes

Functional page JavaScript

7.657 KB 3.334 KB gzip

Always loaded.

Fallback additional

19.389 KB 6.970 KB gzip

Core + selected adapters.

Fallback route total

27.046 KB 10.304 KB gzip

Always-loaded and fallback files; shared files counted once.

Native-surface route total

8.646 KB 3.872 KB gzip

Includes 0.989 KB (0.538 KB gzip) of behavioral probes requested only after the property surface is present.

Minified / gzip. 1 KB = 1,000 bytes. Demo-only syntax highlighting is excluded from the functional totals and reported separately below.

Whole-page delivery context

HTML document

17.919 KB 1 request

Generated markup, including these measurements.

Initial supporting assets

21.802 KB raw 21.179 KB local transfer · 4 requests

Styles, icon, and the highlighting scheduler; functional JS is separate above.

Initial page with fallback

66.767 KB raw 49.402 KB local transfer · 10 requests

Document + functional fallback path + initial supporting assets, with unique files counted once.

Deferred highlighting

16.700 KB raw 7.831 KB local transfer · 8 requests

Engine, theme, and this page’s grammar closure, requested after a source disclosure opens or during idle time.

“Local transfer” matches the included development server: gzip JavaScript sidecars, but uncompressed HTML, CSS, and SVG. GitHub Pages, browser caching, HTTP headers, and production compression can change transferred bytes and request scheduling. Module preloads fetch functional modules early without evaluating the app and do not add duplicate transfers.

Inspect the 6 generated JavaScript files

Selected adapters: form-targets.

Gzip totals sum each compressed file. The fallback and native-probe routes are mutually exclusive. Separate CSS files, HTML, JSON, source maps, HTTP headers, and Microlighter assets are excluded. Component styles embedded in JavaScript are included. Transfer sizes depend on compression and caching. Microlighter MIT license.

Files included in this page’s totals
FileDeliveryMinifiedGzip
forms/main.js Page 3.257 KB 1.351 KB
shared/chunks/app-LI4QCBWX.js Page 4.258 KB 1.845 KB
shared/chunks/chunk-CLCOZ6O7.js Fallback / native probe shared 0.849 KB 0.422 KB
shared/chunks/chunk-S2QLMWTP.js Page 0.142 KB 0.138 KB
shared/chunks/detect-X6QVIAY4.js Native-surface probe 0.140 KB 0.116 KB
shared/chunks/reference-target.setup-6XXBBVEE.js Fallback additional 18.540 KB 6.548 KB

Inspect the size manifest

Implementation notes & limitations

Fallback scope

Forwards submit and reset actions only. External data controls remain unassociated; a temporary inner submitter changes submitter identity and event paths.

Readouts describe DOM state. Check computed names, keyboard behavior and assistive technology separately.