F
Filament9mo ago
Tom

Realtime field validation.

How can I have realtime validation> I am trying with the following with no success. ->afterStateUpdated(function ($livewire) { $livewire->validateOnly('data.public_key'); })
Solution:
```php Textarea::make('public_key') ->label(__('Public Key')) ->maxLength(255) ->rows(10)...
Jump to solution
4 Replies
SirFat
SirFat9mo ago
Seems to be missing context here - what state is being updated to fire that ?
Tom
Tom9mo ago
Textarea::make('public_key')
->label(__('Public Key'))
->maxLength(255)
->rows(10)
->required()
->rules([new PublicKey])
->afterStateUpdated(function ($livewire) {
$livewire->validateOnly('data.public_key');
})
Textarea::make('public_key')
->label(__('Public Key'))
->maxLength(255)
->rows(10)
->required()
->rules([new PublicKey])
->afterStateUpdated(function ($livewire) {
$livewire->validateOnly('data.public_key');
})
Solution
LeandroFerreira
LeandroFerreira9mo ago
Textarea::make('public_key')
->label(__('Public Key'))
->maxLength(255)
->rows(10)
->required()
->rules([new PublicKey])
->live(onBlur: true)
->afterStateUpdated(function ($livewire, $component) {
$livewire->validateOnly($component->getStatePath());
})
Textarea::make('public_key')
->label(__('Public Key'))
->maxLength(255)
->rows(10)
->required()
->rules([new PublicKey])
->live(onBlur: true)
->afterStateUpdated(function ($livewire, $component) {
$livewire->validateOnly($component->getStatePath());
})
Tom
Tom9mo ago
Worked perfectly. I really appreciate it.