#extraModalFooterActions not working

5 messages · Page 1 of 1 (latest)

small bramble
#

What I want to do is customise what happens in the 'Cancel' action of a modal, but I can't find a way to do this. Here is what I've tried so far

TextInput::make('foobar')
    ->required()
    ->suffixAction(\Filament\Forms\Components\Actions\Action::make('something')
        ->requiresConfirmation()
        ->modalCancelAction(fn (StaticAction $action) => $action->label('Close')
            ->action(function() {
                dd('Normal cacnel');
            })
        )
        ->extraModalFooterActions(fn(\Filament\Forms\Components\Actions\Action $action) => [
            StaticAction::make('cancel')
                ->button()
                ->action(function() {
                    dd('Cancel');
                }),
            $action->makeModalAction('cancel2')
                ->action(function () {
                    dd('I said cancel!');
                }),
            \Filament\Actions\Action::make('cancel3')
                ->action(function() {
                    dd('WTF is going on?');
                }),
        ])
        ->action(function () {
            dd('fuck right off');
        }),
    ),

None of the above seems to work. Like, the actions are not even executed. I don't know what I'm missing here. Most of the code is boilerplate or taken directly from the docs.

livid ocean
# small bramble What I want to do is customise what happens in the 'Cancel' action of a modal, b...

use makeModalSubmitAction

TextInput::make('foobar')
    ->required()
    ->suffixAction(\Filament\Forms\Components\Actions\Action::make('something')
        ->requiresConfirmation()
        ->extraModalFooterActions(fn (\Filament\Forms\Components\Actions\Action $action): array => [
            $action->makeModalSubmitAction('cancel1', arguments: ['cancel' => 1]),
            $action->makeModalSubmitAction('cancel2', arguments: ['cancel' => 2]),
        ])
        ->action(function (array $data, array $arguments) {
            dd($data, $arguments);
        }),
    ),

https://filamentphp.com/docs/3.x/actions/modals#adding-an-extra-modal-action-button-to-the-footer

small bramble
livid ocean
small bramble
# livid ocean You can register an event in your Create/Edit page ```php #[On('cancel2Event')]...

This sort of works but it's a bit limited (don't have access to some of the parameters that would be available to an action like Get/Set etc)

Anyway, the way I solved my issue was by applying the validation only after the 'cancel' check. So something like

->action(function (array $data, array $arguments, Set $set, Form $form) {

    if ($arguments['cancel'] ?? false) {
        // Do something here
        return;
    }

    // Apply validation rules
    $form->getComponents()[0]
        ->required();
    $form->validate();

 
    // Rest of the logic
})

This is a hacky workaround, but so was everything else I could think off so ...¯_(ツ)_/¯

Anyway, thank you for your time, really appreciate it ❤️