One-time verification
Collect a six-digit code sent through another channel.
Components / Forms
A multi-cell PIN or one-time-code input with paste and complete handling.
npx @getweini/cli@latest add pin-inputCollect a six-digit code sent through another channel.
Enter a short numeric secret without displaying each character.
<script setup lang="ts">
import { ref } from 'vue'
import PinInput from './components/ui/pin-input/PinInput.vue'
const code = ref('')
const messages = {
character: (index: number, total: number) => 'Digit ' + index + ' of ' + total,
}
function verifyCode(value: string) { console.log(value) }
</script>
<template>
<span id="verification-label">Verification code</span>
<PinInput
v-model="code"
name="verificationCode"
aria-labelledby="verification-label"
:length="6"
:messages="messages"
@complete="verifyCode"
/>
</template>Autofill and paste can populate the six cells.
<script setup lang="ts">
import { ref } from 'vue'
import PinInput from './components/ui/pin-input/PinInput.vue'
const code = ref('')
const messages = { character: (index: number, total: number) => 'Digit ' + index + ' of ' + total }
function verify() { console.log(code.value) }
</script>
<template>
<span id="code-label">Verification code</span>
<PinInput v-model="code" name="code" aria-labelledby="code-label" :length="6" :messages="messages" @complete="verify" />
</template>Application validation still decides whether the value is acceptable.
<script setup lang="ts">
import { ref } from 'vue'
import PinInput from './components/ui/pin-input/PinInput.vue'
const code = ref('')
const messages = { character: (index: number, total: number) => 'Digit ' + index + ' of ' + total }
</script>
<template>
<label id="access-label">Access code</label>
<PinInput v-model="code" aria-labelledby="access-label" :length="4" mask required :messages="messages" />
</template>The most useful props, models, slots, events, and methods for this component.
| Name | Type | Default or requirement |
|---|---|---|
v-model | string | '' |
messages | { character(index, total): string } | required |
length | positive integer | 6 |
type | numeric | text | numeric |
mask | boolean | false |
autocomplete | string | one-time-code |
id / name / form | string | undefined |
required / disabled / readonly / invalid | boolean | false |
size | sm | md | lg | md |
Name the root group and localize every cell label. Typing advances, paste fills forward, navigation keys move focus, and a hidden named input serializes the complete value for forms.