Close modal from List HeaderActions
I'm having problems with closeing a modal inside a list header actions:
The ID is random and unique. So on opening the id changes. Dispatch close is not working.
How to close the modal after the action?
class ListHabits extends ListRecords
{
protected static string $resource = HabitResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('createOrDuplicateHabit')
->label(('Habits'))
->form([
Forms\Components\Tabs::make('habits_tabs')
->tabs([
Forms\Components\Tabs\Tab::make(('Add'))
->schema([]),
Forms\Components\Tabs\Tab::make(('Load from library'))
->schema([
Forms\Components\Grid::make(3)
->schema(),
])
]),
])
->action(function (array $data): void {
if (isset($data['title']) && isset($data['unit'])) {
$habit = new Habit();
//
$habit->save();
Notification::make()
->success()
->title(('Added'))
->body(__('Added'))
->send();
// Close the modal
// ID of the modal is unkown
}
})
];
Solution:Jump to solution
I've managed to create a work around, because the unique / random id of the modal is not retrievable from withint the action (as far as i know)
After save and notification add:
// Refresh the page...
1 Reply
Solution
I've managed to create a work around, because the unique / random id of the modal is not retrievable from withint the action (as far as i know)
After save and notification add:
// Refresh the page
redirect()->to(request()->header('Referer'));
For the cancel button add:
<x-filament::button
type="button"
color="gray"
x-on:click="close()"
>
{{ __('Cancel') }}
</x-filament::button>