© 2026 Hedgehog Software, LLC

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

Conditionally showing TextInput or changing default

I want to show a different default value in the TextInput depending on the organization_type. I have therefore created two TextInput fields. I hide the TextInput depending on the type of organization.
As such this works, but I also need the default value to be different depending on the organization type. While the TextInput is correctly chosen (e.g I can see that on the label), the default value of the first TextInput is always shown.

So concrete: I have two types of organizations (e.g. an individual and a company). When organization type is individual, I want to show a textInput with the name of the individual. When organization type is company, I want to show a textInput with default value of the user name, with "'s Company" added to the default value


     Select::make('organization_type')
                    ->live()
                    ->options(OrganizationType::class)
                    ->required()
                    ->afterStateUpdated(function ($state, Set $set) {
                        $set('organization_type', $state);
                    }),

         TextInput::make('name')
                    ->label('Organization Name')
                    ->default( Filament::getUsername(auth()->user()) . " 's Company")
                    ->visible(fn (Get $get): bool =>
                        $get('organization_type') ===  'company'
                    ),

                TextInput::make('name')
                    ->label('Individual Name')
                    ->default(  Filament::getUsername(auth()->user()) )
                    ->visible(fn (Get $get): bool =>
                        $get('organization_type') === 'individual'
                    ),
                    

     Select::make('organization_type')
                    ->live()
                    ->options(OrganizationType::class)
                    ->required()
                    ->afterStateUpdated(function ($state, Set $set) {
                        $set('organization_type', $state);
                    }),

         TextInput::make('name')
                    ->label('Organization Name')
                    ->default( Filament::getUsername(auth()->user()) . " 's Company")
                    ->visible(fn (Get $get): bool =>
                        $get('organization_type') ===  'company'
                    ),

                TextInput::make('name')
                    ->label('Individual Name')
                    ->default(  Filament::getUsername(auth()->user()) )
                    ->visible(fn (Get $get): bool =>
                        $get('organization_type') === 'individual'
                    ),
                    
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

Disabling TextInput conditionally
FilamentFFilament / ❓┊help
2y ago
Table TextInput Conditionally Disabled
FilamentFFilament / ❓┊help
2y ago
Conditionally display Form TextInput
FilamentFFilament / ❓┊help
3y ago
TextInput default = object?
FilamentFFilament / ❓┊help
3y ago