© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
10 replies
MZX

Conditional Fields

What is wrong here? This isn't working. When the user selects the tier, I want the price to be set automatically.
Forms\Components\Select::make('tier')
                    ->options(Tier::class)
                    ->required()
                    ->reactive()
                    ->afterStateUpdated(function ($state, callable $set) {
                        switch ($state) {
                            case 'standard':
                                $set('price', 14.75);
                                break;
                            case 'advanced':
                                $set('price', 26.54);
                                break;
                            case 'vip':
                                $set('price', 36.87);
                                break;
                        }
                    }),
                Forms\Components\TextInput::make('price')
                    ->label('Price (€)')
                    ->numeric()
                    ->disabled(),
Forms\Components\Select::make('tier')
                    ->options(Tier::class)
                    ->required()
                    ->reactive()
                    ->afterStateUpdated(function ($state, callable $set) {
                        switch ($state) {
                            case 'standard':
                                $set('price', 14.75);
                                break;
                            case 'advanced':
                                $set('price', 26.54);
                                break;
                            case 'vip':
                                $set('price', 36.87);
                                break;
                        }
                    }),
                Forms\Components\TextInput::make('price')
                    ->label('Price (€)')
                    ->numeric()
                    ->disabled(),
Solution
@MZX not related to the question, but
match
match
is nicer than
switch
switch
😉
$price = match ($state) {
    'standard' => 14.75,
    'advanced' => 26.54,
    'vip' => 36.87,
};

$set('price', $price);
$price = match ($state) {
    'standard' => 14.75,
    'advanced' => 26.54,
    'vip' => 36.87,
};

$set('price', $price);

or inline:
$set('price', match ($state) {
    'standard' => 14.75,
    'advanced' => 26.54,
    'vip' => 36.87,
});
$set('price', match ($state) {
    'standard' => 14.75,
    'advanced' => 26.54,
    'vip' => 36.87,
});
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Conditional visibility of form fields
FilamentFFilament / ❓┊help
15mo ago
Fieldset relationship fields doesn't load data
FilamentFFilament / ❓┊help
3y ago
Conditional plugin
FilamentFFilament / ❓┊help
2y ago
conditional configureusing
FilamentFFilament / ❓┊help
2y ago