Component

Confirmation code input

<DomConfirmationCodeInput>

A segmented confirmation-code field with one character per box, automatic focus movement, and full-code paste support.

Playground

Try every prop live

Confirmation code input playground

Use numeric mode for digit-only codes, or keep the default alphanumeric mode for letters and numbers.

Enter the six-character code sent to your email.

Playground.vuevue
vue
<script setup>
import { reactive } from 'vue';
import { DomConfirmationCodeInput } from '@getdom/studio/vue';

const data = reactive({
	  "modelValue": "",
	  "id": "",
	  "name": "",
	  "label": "Confirmation code",
	  "description": "Enter the six-character code sent to your email.",
	  "placeholder": "",
	  "required": false,
	  "disabled": false,
	  "readOnly": false,
	  "invalid": false,
	  "errors": [],
	  "visible": true,
	  "validators": [],
	  "validateOnBlur": true,
	  "chrome": "field",
	  "length": 6,
	  "separatorAfter": 3,
	  "characterSet": "alphanumeric",
	  "uppercase": true,
	  "autocomplete": "one-time-code"
	});
</script>

<template>
	<DomConfirmationCodeInput
		v-bind="data"
		@update:modelValue="data.modelValue = $event"
	/>
</template>

Demo

Email confirmation

Typing advances automatically. Paste and one-time-code autofill distribute a complete code across all six boxes.

Enter the six-character code sent to alex@example.com.

You can also paste the complete code into any box.

vue
<script setup>
import { ref } from 'vue';
import { DomConfirmationCodeInput } from '../../../lib/vue';

const code = ref('');
const completedCode = ref('');

/**
 * Records the complete code so the example can show its completion state.
 *
 * @param {string} value Complete confirmation code.
 * @returns {void}
 */
function onComplete(value) {
	completedCode.value = value;
}
</script>

<template>
	<div class="w-full max-w-sm">
		<DomConfirmationCodeInput
			v-model="code"
			label="Confirmation code"
			description="Enter the six-character code sent to alex@example.com."
			@complete="onComplete"
		/>
		<p
			v-if="completedCode && completedCode === code"
			class="mt-3 text-sm font-medium text-success"
			role="status"
		>
			Code complete: {{ completedCode }}
		</p>
		<p v-else class="mt-3 text-xs text-muted-fg">
			You can also paste the complete code into any box.
		</p>
	</div>
</template>

Reference

Props

Control props

NameTypeTSDefaultDescription
modelValuestringstring''Confirmation code without the visual separator.
lengthnumbernumber6Number of character boxes.
separatorAfternumbernumber3Box position after which to show a visual separator. Use 0 to hide it.
characterSet'alphanumeric' | 'numeric'string'alphanumeric'Characters accepted by the control.
uppercasebooleanbooleantrueConvert entered letters to uppercase.
autocompletestringstring'one-time-code'Native autocomplete hint applied to the first box.

Field props

NameTypeTSDefaultDescription
idstringstring''Optional ID override. By default parent forms derive the input ID from the field path using underscores.
namestringstring''Local field name. Parent forms derive the full field path and native HTML name from the form hierarchy.
labelstringstring''Visible field label.
descriptionstringstring''Optional helper copy below the field.
placeholderstringstring''Placeholder shown when the control is empty.
requiredbooleanbooleanfalseMark the field as required.
disabledbooleanbooleanfalseDisable field interaction.
readOnlybooleanbooleanfalseShow the value but prevent editing.
invalidbooleanbooleanfalseMark the field invalid.
errors
ts
[
	{
		name: "Validation name",
		message: "Error message",
	}
]
array | object | stringArray<ErrorsItem
type ErrorsItem = {
	name?: string; // Name
	message?: string; // Message
};
>
[]Validation errors for this field.
visiblebooleanbooleantrueShow or hide the field.
validatorsarrayArray<unknown>[]Validators attached to this field. Use functions in Vue code, or serializable records such as { name: "minLength", props: { min: 2 } } in generated schemas.
validateOnBlurbooleanbooleantrueRun validators when the field loses focus.
chrome'field' | 'none' | falsestring'field'Render default field chrome, or hide chrome while keeping form state wiring.

Auto-generated from Confirmation code input.props and inline _edit hints.

Events

NamePayloadDescription
@update:modelValuestringFired whenever the entered code changes.
@completestringFired when every character box contains a value.
@focusFocusEventFired when focus enters the segmented control.
@blurFocusEventFired when focus leaves the segmented control.

Names auto-detected from defineEmits and source emit() calls; payload and description from __doc.events when present.

Keyboard

  • CharacterEnter one character and move focus to the next box.
  • BackspaceClear the current box, or move back and clear the previous box when empty.
  • DeleteClear the current box.
  • Left / RightMove between character boxes.
  • Home / EndMove to the first or last character box.
  • PasteDistribute a complete or partial code across the boxes.