Skip to main content
← Back to Table of Contents

Summary

OTP / verification code input with grouped digit boxes, paste support, optional auto-submit, loading indicator, and optional account-verify chrome (heading, description, footer link action).
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\FlexVerificationCode
State typestring — normalized code (no separators)
Model cast'verification_code' => 'string'
FieldTypeverification_code
Playgroundverification-code slug in Flex Fields playground

Basic usage

Standard 6-digit OTP

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexVerificationCode;

FlexVerificationCode::make('otp')
    ->label('Verification code')
    ->length(6)
    ->groups([3, 3])
    ->groupSeparator('-')
    ->required();

Alphanumeric with auto-submit

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\FlexVerificationCode;

FlexVerificationCode::make('backup_code')
    ->length(8)
    ->allowedCharacters('alphanumeric')
    ->autoSubmit()
    ->autoSubmitMethod('verifyOtp')
    ->loading();

State & validation

Stored value

State is a normalized string of exactly length() characters. Separators are display-only.
$record->verification_code; // string — e.g. "123456"

Validation rules

CheckDetail
required()Non-empty after normalization
CharactersMust match allowedCharacters pattern (numeric or alphanumeric)
LengthExactly length() when non-empty

Configuration API

All methods accept Closure unless noted.
MethodTypeDefaultDescription
length(int|Closure $length)Setup6Total characters (1–16)
groups(array|Closure|null $groups)Setup[3, 3]Group sizes summing to length()
groupSeparator(string|Closure|null $separator)Setup'-'Visual separator between groups
allowedCharacters(string|Closure $allowedCharacters)Setup'numeric'numeric or alphanumeric
color(string|Closure|null $color)Setup'primary'Accent color for active digit
autoSubmit(bool|Closure $condition = true)SetupfalseSubmit when all digits are filled
autoSubmitMethod(string|Closure|null $method)SetupnullLivewire method to call on completion
submitUsing(Closure $callback)SetupnullPHP callback to run on completion
loading(bool|Closure $condition = true)SetupfalseShow spinner during Livewire requests
heading(string|Htmlable|Closure|null $heading)SetupnullTitle above the inputs
description(string|Htmlable|Closure|null $description)SetupnullSupporting copy below the heading
footer(string|Htmlable|Closure|null $footer)SetupnullMuted text before the footer action
footerAction(Action|Closure|null $action)SetupnullLink-style action beside the footer text
size(string|ControlSize|Closure $size)Setup'md'Control size: sm, md, lg
rounding(string|Closure|null $rounding)SetupconfigBorder radius token

submitUsing()

Run a PHP callback when the code is complete. Inject $state, $livewire, $set, etc.
FlexVerificationCode::make('code')
    ->submitUsing(function (string $code, $livewire) {
        $livewire->verifyCode($code);
    });

footerAction()

Register a link-style action (e.g. Resend):
FlexVerificationCode::make('otp')
    ->footer("Didn't receive a code?")
    ->footerAction(fn () => $livewire->resendCode());

Real-world examples

Account verification screen

FlexVerificationCode::make('otp')
    ->hiddenLabel()
    ->heading('Verify your account')
    ->description("We've sent a 6-digit code to your email.")
    ->footer("Didn't receive it?")
    ->footerAction(fn () => /* resend logic */)
    ->length(6)
    ->autoSubmit();

2FA backup codes

FlexVerificationCode::make('backup_code')
    ->length(8)
    ->allowedCharacters('alphanumeric')
    ->groups([4, 4])
    ->groupSeparator(' ');

Playground

/admin/flex-fields-playground/verification-code See Playground for setup.
ComponentWhen to use instead
FlexTextInputFor standard single-line text inputs
PhoneFieldFor entering phone numbers
NumberStepperFor incrementing/decrementing numeric values

CSS classes (reference)

ClassRole
fff-verification-codeDigit inputs root
fff-verification-code__inputSingle digit cell
fff-verification-code__separatorGroup separator
fff-verification-code-layoutVertical stack for heading/footer chrome
fff-verification-code-layout__headingTitle
fff-verification-code-layout__footerFooter row

Performance

MechanismWhat it does
Smart PasteDistributes pasted codes across cells instantly
Auto-focusAutomatically moves focus to the next cell after input
Zero FlashServer-renders the digit cells to prevent layout shifts