TextInput afterStateUpdated() reactive weird behavior

I have copied a well-functional code from my V2 app. But I have this weird behavior in V3 The text goes back and forth. The code works really well in V2. I have tested it also in a freshly installed Laravel and Filament V3.
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')->reactive()
->afterStateUpdated(function ($set, $state) {
$set('slug', Str::slug($state));
}),
Forms\Components\TextInput::make('slug')->required()->disabled(),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')->reactive()
->afterStateUpdated(function ($set, $state) {
$set('slug', Str::slug($state));
}),
Forms\Components\TextInput::make('slug')->required()->disabled(),
]);
}
32 Replies
LeandroFerreira
what about this?
Forms\Components\TextInput::make('name')
->live(debounce: 500)
->afterStateUpdated(function (\Filament\Forms\Set $set, ?string $state) {
$set('slug', Str::slug($state));
}),

Forms\Components\TextInput::make('slug')
->disabled()
Forms\Components\TextInput::make('name')
->live(debounce: 500)
->afterStateUpdated(function (\Filament\Forms\Set $set, ?string $state) {
$set('slug', Str::slug($state));
}),

Forms\Components\TextInput::make('slug')
->disabled()
neverender24
neverender24OP2y ago
It can ease, the problem when you hit the backspace to delete text, the text won't delete, it keeps reapearing
neverender24
neverender24OP2y ago
LeandroFerreira
with ->live(debounce: 500) ?
neverender24
neverender24OP2y ago
in both, yes even with debounce.
LeandroFerreira
fresh install? Filament version? What is your browser?
neverender24
neverender24OP2y ago
Yes fresh install. Windows 10, Laragon, I tested it in both Microsoft Edge and Chrome same results.
neverender24
neverender24OP2y ago
I let my friend to test it also in his workstation, same result.
LeandroFerreira
share the whole code you are trying please
neverender24
neverender24OP2y ago
I updated my post
LeandroFerreira
?
neverender24
neverender24OP2y ago
<?php namespace App\Filament\Resources; use Filament\Forms; use Filament\Tables; use App\Models\Drawer; use Filament\Forms\Form; use Filament\Tables\Table; use Illuminate\Support\Str; use Filament\Resources\Resource; use Illuminate\Database\Eloquent\Builder; use App\Filament\Resources\DrawerResource\Pages; use Illuminate\Database\Eloquent\SoftDeletingScope; use App\Filament\Resources\DrawerResource\RelationManagers; class DrawerResource extends Resource { protected static ?string $model = Drawer::class; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; public static function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('name')->reactive() ->afterStateUpdated(function ($set, $state) { $set('slug', Str::slug($state)); }), Forms\Components\TextInput::make('slug')->required()->disabled(), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('name') ->searchable(), Tables\Columns\TextColumn::make('slug') ->searchable(), Tables\Columns\TextColumn::make('office_id') ->numeric() ->sortable(), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]) ->emptyStateActions([ Tables\Actions\CreateAction::make(), ]); }
public static function getRelations(): array { return [ // ]; }
public static function getPages(): array { return [ 'index' => Pages\ListDrawers::route('/'), 'create' => Pages\CreateDrawer::route('/create'), 'edit' => Pages\EditDrawer::route('/{record}/edit'), ]; }
} I can't seem to update it longer text I just segemented it but here it is
LeandroFerreira
where is debounce?
neverender24
neverender24OP2y ago
I just undo it, sorry public static function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('name') ->live(debounce: 500) ->afterStateUpdated(function (\Filament\Forms\Set $set, ?string $state) { $set('slug', Str::slug($state)); }), Forms\Components\TextInput::make('slug') ->disabled() ]); } it goes like this
LeandroFerreira
the same Filament version here and it is working.. there is no issues for me
neverender24
neverender24OP2y ago
I have my friend tested it also fresh install and we have both same results
LeandroFerreira
can you share this project on github?
neverender24
neverender24OP2y ago
okay sure let me make repo Okay I have my second friend test it on MAC, and it has no problem me and my first friend both on windows
neverender24
neverender24OP2y ago
GitHub
GitHub - PLGUPICTO/archive_filamentv3
Contribute to PLGUPICTO/archive_filamentv3 development by creating an account on GitHub.
neverender24
neverender24OP2y ago
@Leandro Ferreira @Leandro Ferreira I think we got it, I have my team tested it and it seems some pc with low specs having the problem. Others pc with good specs no problem. So we can't really use filament well with low-end pc 😦
toeknee
toeknee2y ago
Make it lazy and slug disabled from custom input
toeknee
toeknee2y ago
Exactly People really shouldn't be using live/reactive so much when theres a lot of typing 🙂
neverender24
neverender24OP2y ago
This is our first attempt with filament so we don't know yet the limitations. Coming from vue inertia
Pieter
Pieter2y ago
Yes but for this implementation its not desirable to have it lazy(). Because lazy only sets when you move away from the field. If these are the only 2 fields you want to use you might want to look into field lifecycles and mutating data before creating.
neverender24
neverender24OP2y ago
Yeah, I think we go this way
toeknee
toeknee2y ago
I disagree, you don't actually need to see or adjust the slug. The slug is the slug, so when clicking it to type it, it will have updated.
neverender24
neverender24OP2y ago
Btw, I don't have this problem in V2, I just copy the code from there
LeandroFerreira
working here with debounce 🤷‍♂️
neverender24
neverender24OP2y ago
CanI mention you to the other help post I made?
xy
xy2y ago
debounce(600) fixed this for me
jamesj2
jamesj24w ago
full_name

Did you find this page helpful?