WlInputOtp

One form field with visual cells for a short numeric code.
Components / Inputs v1.4.0

Limits

Type or paste the code as one field. FormData receives a string with leading zeros. The application verifies the code.

Full example
<script setup lang="ts">
import { WlButton, WlField, WlInputOtp } from "legato-ui";
import { ref } from "vue";
const code = ref("");
const submitted = ref("");
function submit(event: Event): void {
  if (event.currentTarget instanceof HTMLFormElement) {
    submitted.value = String(new FormData(event.currentTarget).get("code") ?? "");
  }
}
</script>

<template>
  <form class="wl-stack" data-space="md" @submit.prevent="submit">
    <WlField v-slot="{ id, labelId }" label="Verification code">
      <WlInputOtp
        :id="id"
        v-model="code"
        name="code"
        :length="6"
        :aria-labelledby="labelId"
        
      />
    </WlField>
    <div><WlButton type="submit">{{ "Send code" }}</WlButton></div>
    <output v-if="submitted" aria-label="Verification code">{{ submitted }}</output>
  </form>
</template>

States

Full example
<script setup lang="ts">
import { WlButton, WlField, WlInputOtp } from "legato-ui";
import { ref } from "vue";
const code = ref("");
const submitted = ref("");
function submit(event: Event): void {
  if (event.currentTarget instanceof HTMLFormElement) {
    submitted.value = String(new FormData(event.currentTarget).get("code") ?? "");
  }
}
</script>

<template>
  <form class="wl-stack" data-space="md" @submit.prevent="submit">
    <WlField v-slot="{ id, labelId }" label="Verification code">
      <WlInputOtp
        :id="id"
        v-model="code"
        name="code"
        :length="6"
        :aria-labelledby="labelId"
        
      />
    </WlField>
    <div><WlButton type="submit">{{ "Send code" }}</WlButton></div>
    <output v-if="submitted" aria-label="Verification code">{{ submitted }}</output>
  </form>
</template>

React to a complete code

The complete event sends the whole code as a string, including its leading zeros.

Type or paste four digits, such as 0042.
Full example
<script setup lang="ts">
import { WlField, WlInputOtp } from "legato-ui";
import { ref } from "vue";

const code = ref("");
const completed = ref("");
</script>

<template>
  <div class="wl-stack" data-space="sm">
    <WlField
      v-slot="{ id, ariaDescribedby }"
      label="Verification code"
      hint="Type or paste four digits, such as 0042."
    >
      <WlInputOtp
        :id="id"
        v-model="code"
        :length="4"
        :aria-describedby="ariaDescribedby"
        @complete="completed = $event"
      />
    </WlField>
    <output v-if="completed" class="wl-text-small" aria-label="Last complete code">
      {{ "Last complete code" }} <code>{{ completed }}</code>
    </output>
  </div>
</template>