FilamentF
Filament3y ago
eazy

Dynamic text input value

I have the following form:
        return [
            TextInput::make('year')
                ->label(__('Year'))
                ->numeric()
                ->reactive()
                ->required(),
            TextInput::make('name')
                ->label(__('Name'))
                ->numeric()
                ->reactive()
                ->required(),
            TextInput::make('code')
                ->reactive()
                ->afterStateHydrated(function (TextInput $component, Closure $get) {
                    $year = $get('year');
                    $name = $get('name');
                    if ($year !== null && $name !== null) {
                        $component->state('xxx');
                    }
                    $component->state('123');
                })
                ->disabled()
        ];


I want my code field's value change when the year and
name
input gets a value. If the year and
name
input is empty I want to show nothing. How can I achieve this?
Was this page helpful?