useInlineEdit
Headless edit-in-place state machine managing four states — IDLE, EDITING, VALIDATING, ERROR — and four transitions: edit, confirm, cancel, setValue. Input-agnostic: it owns the draft string and the async validation pipeline; components wire their native input to the returned draft ref.
API
Signature
Full TypeScript signature sourced from the composable file.
When both rules and validate are provided, rules are evaluated first sequentially; validate is only reached if all rules pass. Stale async validations are cancelled via an internal token counter — calling cancel() mid-flight safely discards the in-flight Promise.
Consumed interfaces
API
Parameters
Input parameters accepted by this composable.
- modelValuerequiredRef<string | number> | ComputedRef<string | number>
- The current committed value (the v-model source). Snapshotted into draft when edit() is called.
- optionsMaybeRefOrGetter<IUseInlineEditOptions>{}
- Optional configuration: trim, validate, rules, onConfirm, onCancel, onError callbacks.
- options.trimbooleantrue
- Trims whitespace from the draft before validation and confirmation.
- options.validateTInlineEditValidator
- Async validation callback. Receives the normalised draft value and must return true (valid) or an error string.
- options.rulesTInlineEditRule[]
- Array of rule functions evaluated sequentially before validate. Each rule returns true or an error string.
- options.onConfirm(value: string) => void
- Called with the confirmed value when all validations pass. Wire to emit("update:modelValue", value) in the SFC.
- options.onCancel() => void
- Called when the user cancels editing without confirming.
- options.onError(message: string) => void
- Called when validation fails, with the error message string.
API
Return values
Properties and methods exposed by the composable return object.
- isEditing
- True while the component is in editing mode.
- draft
- The mutable editing buffer. Bind to the native input value and update via setValue on oninput.
- error
- Current validation error message, or null when there is no error.
- isPending
- True while an async validator is running.
- normalisedDraft
- The trimmed version of draft (when trim is true). Used as the validated and committed value.
- isDraftEmpty
- True when the normalised draft is an empty string.
- edit
- Enters edit mode, snapshotting modelValue into draft. No-op if already editing.
- confirm
- Runs rules then validate sequentially. On success, calls onConfirm and exits edit mode. Returns true on success, false on validation failure.
- cancel
- Discards the draft, resets all state, and calls onCancel.
- setValue
- Updates draft and clears any stale error. Called from the oninput handler.
Usage
Examples
Ready-to-paste usage snippets.
Basic inline edit field
With async server validation