Skip to content

Commit

Permalink
[ADD] Support input type
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-ahani committed Feb 6, 2024
1 parent 87d8ee7 commit 659e1fa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ public function form(Form $form): Form
}
```


## 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:
```php
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

```bash
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/otp-input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$statePath = $getStatePath();
$numberInput = $getNumberInput();
$isAutofocused = $isAutofocused();
$inputType = $getType();
@endphp

<x-dynamic-component
Expand All @@ -31,6 +32,7 @@
state: $wire.$entangle('{{ $getStatePath() }}'),
length: {{$numberInput}},
autoFocus: '{{$isAutofocused}}',
type: '{{$inputType}}',
init: function(){
if (this.autoFocus){
this.$refs[1].focus();
Expand Down Expand Up @@ -100,7 +102,7 @@
"
>
<input
type="number"
type="{{$inputType}}"
maxlength="1"
x-ref="{{$column}}"
required
Expand Down
21 changes: 21 additions & 0 deletions src/Components/OtpInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class OtpInput extends Field implements Contracts\CanBeLengthConstrained, Contra
protected int | \Closure | null $numberInput = 4;


protected string | \Closure | null $type = 'number';


public function numberInput(int | \Closure $number = 4):static
{
$this->numberInput = $number;
Expand All @@ -35,4 +38,22 @@ public function getNumberInput():int
return $this->evaluate($this->numberInput);
}


public function password(): static
{
$this->type = 'password';
return $this;
}

public function text(): static
{
$this->type = 'text';
return $this;
}

public function getType(): string
{
return $this->evaluate($this->type);
}

}

0 comments on commit 659e1fa

Please sign in to comment.