interface FieldHandle<TValue> A field bound by useField.
Properties
value
value: TValue; The draft while one exists, otherwise the member's value in the View's state. Setting it is an input by the user, as bind:value and bind:checked do.
text
text: string; What a text input shows: the text typed while it does not parse or still means value (so 1. stays while typing 1.5), otherwise value formatted. Setting it is an input of text, parsed for the field's kind.
editing
readonly editing: boolean; True while a draft exists, from the first input until the last write settled and the state caught up, and after a failed write. Keep the input enabled while it is true, rather than disabling it on the View's busy state.
error
readonly error: unknown; Why the latest write or text failed (a BridgeError or a FieldError), until the next input, retry() or reset().
errors
readonly errors: readonly string[]; The member's validation messages in the View's state, or of the last checked write's receipt; [] when valid.
conflict
readonly conflict: FieldBaseline<TValue> | undefined; The producer's field while a checked write's conflict keeps the draft; undefined otherwise.
validating
readonly validating: boolean; The member's validation is in progress, such as an asynchronous rule that is still checking: show "checking…".
attach
readonly attach: Attachment<FieldElement>; Wires an <input>, <textarea> or <select> to the field: <input {@attach title.attach}>. It writes the text typed (input events; change of a <select> or checkbox, whose checked is the value), writes nothing during IME composition, commits on blur, keeps the element's text (a checkbox's checked) equal to the field's without moving the caret while it already shows it, and sets aria-invalid while the field has errors or an error.
Methods
input
input(value: TValue): void; The user changed the value.
commit
commit(): Promise<FieldState<TValue>>; The user is done with the field (attach calls it on blur): with commit: "pause" the draft is written now. Resolves with the field's state once its writes settled, so a command that depends on the field can run after it and skip a failed write: if ((await title.commit()).error === undefined) await editor.save(). Never rejects; a failure is error.
retry
retry(): void; Writes the draft again after a failed write; after a conflict, over the producer's value.
reset
reset(): void; Drops the draft, the error and a conflict and shows the View's value. Writes in flight still complete.