How can I add a debounce to my autosaving form field?
I have set up a filament form using Livewire. It has one textinput which autosaves when the user types anything. However I'd really like to add a debounce, so it only saves when the user has stopped typing to 0.5 seconds.
Is this possible?
PHP Livewire component class
class UsernameEntry extends Livewire\Component implements HasForms
{
use InteractsWithForms;
...
public function form(Form $form): form
{
return $form->schema([
TextInput::make('username')
->live(),
])->statePath('data');
$this->dispatch('showSaveMessage');
}
public function updatedData($value): void
{
$this->application->username = $value;
$this->application->save();
}
}
Blade Livewire component
<form wire:submit="save">
{{ $this->form }}
</form>
2 Replies
Solution
Thanks that's exactly it.