toolmark-monorepo / @toolmark/core/dom / domFormAdapter
Function: domFormAdapter()
domFormAdapter(
form,opts?):DomFormAdapter
Defined in: packages/core/src/dom/form-adapter.ts:74
Adapts an uncontrolled (or framework-controlled) DOM form to form tools (spec §8.1, §10.2).
- Fields are the named controls of
form.elements(form=-associated controls and form-associated custom elements included). Hidden (e.g. CSRF_token), password (also after a "show password" toggle),autocompletecc-*/current-password/new-password/one-time-code, disabled and[data-tool-ignore]controls are never read, reported or written. Read-only fields (readonlyoraria-readonly="true"on any of their controls) are read (getValues,fields()) as context but never written. Names map to dot paths (a[b]→a.b,a[0][b]→a.0.b;a[]or a repeated name → an array;fieldset[name]prefixes its descendants). setValueswrites through the prototypes' native setters (text,select,option.selected,filesviaDataTransfer) and dispatches bubblinginputandchange; checkboxes and radios whose state must change areclick()ed, so React-controlled inputs update their state.dirtyPaths= fields whose value differs from the load snapshot and is not the value the agent last set, plus fields touched by trusted (isTrusted)input/changeevents; a formreset(not cancelled) re-snapshots and clears both. This protects the user's edits from being overwritten; it is not a security boundary — synthetic events are ignored, but page scripts can still change values (reported through the snapshot diff) or trigger trusted events.submit(default):form.checkValidity()fails →invalidwith each invalid field'svalidationMessageat its path (an excluded or read-only control is reported at""without its name); elseform.requestSubmit()→ok({ submitted: true }).onUserInteraction(tour hooks, spec §13) reports trusted (isTrusted)inputandfocusinevents on a field ({ path, kind: 'input' | 'focus' }) and a trustedsubmitof the form ({ path: '', kind: 'submit' }). Events caused by the adapter's ownsetValuesandsubmitare never reported, nor are events on excluded controls (password,cc-*, hidden, disabled,[data-tool-ignore]): those fields do not exist for tools. Only paths are reported, never values. Note thatelement.focus()from page script also yields a trustedfocusin. The trustedsubmitcaused by a DOM button tool'sclick()(an agent activation) is not reported either. While subscribed, the control → path map is cached and invalidated by aMutationObserveron the form's root.
Parameters
form
HTMLFormElement
The form element.
opts?
Optional submit override.
Returns
The adapter; call dispose() when the form goes away.