F
Filamentβ€’7mo ago
gemini.dev

How to change a label for a field, in view page?

I have a Main Resource file, that defines the form like so (See attached image). I am needing to change the field label only when viewing a record, based on a if condition on what the value of this record is. For example: If value is FR then the label should be Company Registration France. How can I achieve so in the View Page file? <?php namespace App\Filament\Resources\AllClientsResource\Pages; use App\Filament\Resources\AllClientsResource; use Filament\Resources\Pages\ViewRecord; class ViewClient extends ViewRecord { protected static string $resource = AllClientsResource::class; protected function mutateFormDataBeforeFill(array $data): array { return $data; } }
No description
4 Replies
dissto
disstoβ€’7mo ago
I guess you could do something like that:
Select::make('company_registration_country')
->live()
->label(function (Get $get, Select $component, $state){
// if you simply want the country code
return 'Company Registration ' . $get('company_registration_country');

// or you probably want the actual name of the country as opposed to the country code
return 'Company Registration ' . ($component->getOptions()[$state] ?? null);
})
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
]),
Select::make('company_registration_country')
->live()
->label(function (Get $get, Select $component, $state){
// if you simply want the country code
return 'Company Registration ' . $get('company_registration_country');

// or you probably want the actual name of the country as opposed to the country code
return 'Company Registration ' . ($component->getOptions()[$state] ?? null);
})
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
]),
πŸ€”
gemini.dev
gemini.devOPβ€’7mo ago
Thanks @dissto !
LeandroFerreira
LeandroFerreiraβ€’7mo ago
Select::make('company_registration_country')
->live()
->label(fn (Select $component, ?string $state) => 'Company Registration '.(filled($state) ? $component->getOptionLabel() : ' Country'))
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
])
Select::make('company_registration_country')
->live()
->label(fn (Select $component, ?string $state) => 'Company Registration '.(filled($state) ? $component->getOptionLabel() : ' Country'))
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
])
gemini.dev
gemini.devOPβ€’7mo ago
Thank you 😊
Want results from more Discord servers?
Add your server