Inside the shadow root
This example requires a browser that parses declarative shadow DOM.
Browser experiments & working notes
06 / Form actions
Submit or reset an internal form from outside its component.
form="host"#formPreparing the controls…
Automatic checks for the native property. Force fallback loads the selected adapters. Browser alone leaves them out.
Form actions
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.
This example requires a browser that parses declarative shadow DOM.
Controls stay disabled until the form’s handlers are ready.
button.form gettersWaiting for setup…
No submission yet. The submit handler cancels navigation and reads native FormData synchronously.
No submit event yet.
Reset restores the name, an empty email, a weekly digest, and the checked updates box.
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.
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;
}
Always loaded.
Core + selected adapters.
Always-loaded and fallback files; shared files counted once.
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.
Generated markup, including these measurements.
Styles, icon, and the highlighting scheduler; functional JS is separate above.
Document + functional fallback path + initial supporting assets, with unique files counted once.
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.
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.
| File | Delivery | Minified | Gzip |
|---|---|---|---|
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 |
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.