© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
3 replies
Wim

Update a field based on select value

I have a field called 'Country' where a user can select a value. When a user selects a country, it gets stored in the database.


Select::make('country')
       ->required()
        ->native(false)
        ->options(Country::class)
        ->dehydrated(false),

Select::make('country')
       ->required()
        ->native(false)
        ->options(Country::class)
        ->dehydrated(false),

I want to write a two letter country code to another field in the database (e.g country_iso) each time the user selects a value in the above select box. So if a user selects 'Netherlands' I want to write 'Netherlands' to the 'country' field, but also 'NL' in the billing_country.

As a test, in the below snippet, I tried to update the Text Input to display the selected option but that does not work.


Select::make('country')
           ->required()
           ->native(false)
           ->options(Country::class)
           ->dehydrated(false)
           ->afterStateUpdated(function (Set $set, ?string $state) {
                    $set('country', $state);
                    $set('billing_country_placeholder', $state ? "Selected country: $state" : 'No country selected');
            }),
                                

          TextInput::make('billing_country')
                ->live()
                 ->placeholder(fn (Get $get): string => $get('billing_country_placeholder') ?? 'No country selected')

Select::make('country')
           ->required()
           ->native(false)
           ->options(Country::class)
           ->dehydrated(false)
           ->afterStateUpdated(function (Set $set, ?string $state) {
                    $set('country', $state);
                    $set('billing_country_placeholder', $state ? "Selected country: $state" : 'No country selected');
            }),
                                

          TextInput::make('billing_country')
                ->live()
                 ->placeholder(fn (Get $get): string => $get('billing_country_placeholder') ?? 'No country selected')
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Update TextInput based on Select value
FilamentFFilament / ❓┊help
3y ago
Hiding a section based on Select field value
FilamentFFilament / ❓┊help
3y ago
Select Option Disabled Based on Another Field's Value
FilamentFFilament / ❓┊help
12mo ago