FieldHandle interface

Module @runic-artifex/vue in @runic-artifex/vue 0.23.0

interface FieldHandle<TValue>

A field bound by useField: a reactive object, so a template binds its members directly, such as v-model="title.value".

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 v-model does: a string set on a field that is not text (such as from <input type="number"> while its text does not parse) is the field's text, as text is.

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: bind number inputs with v-model="step.text". The number v-model sets on <input type="number"> once its text is one is an input of that value.

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…".

Methods

input

input(value: TValue): void;

The user changed the value.

commit

commit(): Promise<FieldState<TValue>>;

The user is done with the field (@blur="title.commit"): 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.