F
Filament17mo ago
xy

live() causes field to replace text

The following example from docs (for slug field) is causing the title field to refresh, the letters are erased.
Forms\Components\TextInput::make('title')
->live()
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
}),

Forms\Components\TextInput::make('slug'),
Forms\Components\TextInput::make('title')
->live()
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
}),

Forms\Components\TextInput::make('slug'),
4 Replies
Dennis Koch
Dennis Koch17mo ago
Can you sahre a video of the issue? Please also read #✅┊rules on code formatting.
xy
xyOP17mo ago
I am typing in "hi my name is"
awcodes
awcodes17mo ago
I’d recommend using debounce on live in this case so it doesn’t make a request on every keystroke. Debounce will allow it to only make the request when the user stops typing for a defined length of time. https://filamentphp.com/docs/3.x/forms/advanced#debouncing-reactive-fields
xy
xyOP17mo ago
Makes perfect sense, thanks!
Want results from more Discord servers?
Add your server