solution-forest / filament-otp-input
Otp input for filament
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 13
Open Issues: 0
Language:Blade
Requires
- php: ^8.1
- filament/forms: ^3.0
- illuminate/contracts: ^10.0|^11.0|^12.0
- phpstan/phpdoc-parser: ^2.1
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- larastan/larastan: ^2.6|^3.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.0|^8.0|^9.0
- orchestra/testbench: ^v8.9.1|^v9.0.0|^v10.0.0
- pestphp/pest: ^v2.24.3|^v3.0.0
- pestphp/pest-plugin-laravel: ^2.2|^3.0.0
- pestphp/pest-plugin-livewire: ^2.1|^3.0.0
- sinnbeck/laravel-dom-assertions: ^2.0
- spatie/laravel-ray: ^1.31
README
filament-otp-input
is a package built for Filament that provides a One-Time Passcode (OTP) input form component that offers you the ability to add the following features:
- Customize the number of inputs
- Perform an action after filling the code
- Move to the next input after filling
- Move to the previous input with backspaces
Installation
Requires PHP 8.2+, and Laravel 11.0+.
You can install the package via composer:
composer require solution-forest/filament-otp-input
Usage
Inside a form schema, you can use the Otp input like this:
use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;
public function form(Form $form): Form
{
return $form
->schema([
// ...
OtpInput::make('otp')
->label('Otp'),
]);
}
The code above will render a otp input inside the form.
Number inputs
If the number of entries you want is less or more than the default 4 numbers, you can change it according to the example below
use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;
public function form(Form $form): Form
{
return $form
->schema([
// ...
OtpInput::make('otp')
->numberInput(6)
->label('Otp'),
]);
}
The above code creates 6 inputs for entering the OTP code.
Get Code
If you need to receive the code after entering it completely, proceed as in the example below
use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;
public function form(Form $form): Form
{
return $form
->schema([
// ...
OtpInput::make('otp')
->numberInput(8)
->afterStateUpdated(function (string $state){
dd($state);
// submit form or save record
})
->label('Otp'),
]);
}
Input type
By default, the input type is set to "number". If you need to change it to "password" or "text", you can use the following methods:
use HasanAhani\FilamentOtpInput\Components;
use Filament\Forms\Form;
public function form(Form $form): Form
{
return $form
->schema([
// ...
OtpInput::make('otp')
->password()
// or
->text()
->label('Otp'),
]);
}
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.