F
Filament6mo ago
TDT

Create a modal to show error while mounting options of a `Forms\Components\Select`

I'm dynamically mounting options for a Forms\Components\Select component by requesting an API. However the API call can fail, of course, and I need to handle that giving some information to the user. It's important to cite that this select component is inside a modal form for editing the record of a table. However it seems that multiple modals are allowed since it works if add a create option on the same select component. My code is like below:
\Filament\Forms\Components\Select::make('field')
->hiddenLabel()
->options(function () {
try {
$optionsFromApi = [1, 2, 3]; // api call here

return $optionsFromApi;

} catch (ApisException $ex) {
\Filament\Actions\Action::make('error')
->modalHeading('Error')
->modalDescription($ex->getMessage());

return null;
}
})
->searchable()
->preload(),
\Filament\Forms\Components\Select::make('field')
->hiddenLabel()
->options(function () {
try {
$optionsFromApi = [1, 2, 3]; // api call here

return $optionsFromApi;

} catch (ApisException $ex) {
\Filament\Actions\Action::make('error')
->modalHeading('Error')
->modalDescription($ex->getMessage());

return null;
}
})
->searchable()
->preload(),
But the modal is never shown. I already tried to use ->requiresConfirmation() just to test and also ->dispatch('open-modal') and ->dispatchSelf('open-modal'), but none of these worked. However if I use ->action(fn () => info('action called')) and ->call() the action is properly executed despite the modal never is shown. Anyone can help? Am I missing something? Link to the same post on GitHub: https://github.com/filamentphp/filament/discussions/10586
GitHub
Create a modal to show error while mounting options of a `Forms\Com...
I'm dynamicaly mounting options for a Forms\Components\Select component by requesting an API. However the API call can fail, of course, and I need to handle that giving some information to the ...
0 Replies
No replies yetBe the first to reply to this messageJoin