FilamentF
Filament2y ago
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' ),
Was this page helpful?