Conditional requiresConfirmation ignored

I have a conditional requiresConfirmation, but it seems to be overruled by modalDescription. Even if I do requiresConfirmation(false) or remove it entirely, the confirmation pops up. The only way I can get it to work is by putting the condition in modalDescription, but that doesnt make sense for other users. Pseudo code:
Action::make()
->requiresConfirmation(fn (User $user) => $user->shouldShowConfirmation)
->modalDescription('foo')
Action::make()
->requiresConfirmation(fn (User $user) => $user->shouldShowConfirmation)
->modalDescription('foo')
requiresConfirmation is ignored if modalDescription is not null
43 Replies
bernhard
bernhard2w ago
Can't reproduce. I just added the Action to the getHeaderActions array on a Edit-Page:
use Filament\Actions\Action;

Action::make("xx")
->requiresConfirmation(fn (User $user) => true)
->modalDescription(null)
use Filament\Actions\Action;

Action::make("xx")
->requiresConfirmation(fn (User $user) => true)
->modalDescription(null)
And I get the confirmation modal.
rgeraads
rgeraadsOP2w ago
what do you get if you flip it around? requiresConfirmation resulting in false and modalDescription being filled
bernhard
bernhard2w ago
same
rgeraads
rgeraadsOP2w ago
that's wrong, the modal should not be shown
bernhard
bernhard2w ago
What? There is no modal at all, because there is no modal content
rgeraads
rgeraadsOP2w ago
use Filament\Actions\Action;

Action::make("xx")
->requiresConfirmation(fn (User $user) => false)
->modalDescription('test')
use Filament\Actions\Action;

Action::make("xx")
->requiresConfirmation(fn (User $user) => false)
->modalDescription('test')
do you get the modal if you try this?
bernhard
bernhard2w ago
yes because now you have a modal content
rgeraads
rgeraadsOP2w ago
isn't the modal content just placeholder text? ->modalDescription('are you sure you want to do this?')
bernhard
bernhard2w ago
Ok. I think you missunderstand the thing. An Action is just an Action, not necessarily a Modal Opener. So Action::make("xx") does nothing at all
rgeraads
rgeraadsOP2w ago
i want to have a conditional confirmation, and i want to have a customized confirmation message
bernhard
bernhard2w ago
Adding a requiresConfirmation to it, just makes a confirmation modal, to confirm that you dont do anything at all Adding a modalDescription will open another modal - if confirmed. confirmation message -> use filament notifications instead
rgeraads
rgeraadsOP2w ago
I get the same behaviour if I do this:
use Filament\Actions\Action;

Action::make("xx")
->modalDescription('test')
use Filament\Actions\Action;

Action::make("xx")
->modalDescription('test')
rgeraads
rgeraadsOP2w ago
yes this is exactly what i did that's why i think this is a bug
LeandroFerreira
where is the action() method in your code? where are you using this action?
rgeraads
rgeraadsOP2w ago
in my form as a suffixAction on a textInput and in protected function getFormActions(): array
rgeraads
rgeraadsOP2w ago
I do use that the example is merely an example
bernhard
bernhard2w ago

TextInput::make('zip')
->suffixAction(
\Filament\Forms\Components\Actions\Action::make("xxx")
->requiresConfirmation(fn() => true)
->modalDescription("test")
),

TextInput::make('zip')
->suffixAction(
\Filament\Forms\Components\Actions\Action::make("xxx")
->requiresConfirmation(fn() => true)
->modalDescription("test")
),
this shows me the confirmation modal without the modalDescription as well
LeandroFerreira
are you using this in the Panel builder or only in the Form Builder? custom page or resource?
rgeraads
rgeraadsOP2w ago
resource -> form builder
LeandroFerreira
👆 Didn't it work?
rgeraads
rgeraadsOP2w ago
i dont want the confirmation to show in some conditions but it always pops up
TextInput::make('test')
->suffixAction(
Action::make('test')
->requiresConfirmation(fn () => false)
->modalDescription(function () {
return 'test';
})
)
TextInput::make('test')
->suffixAction(
Action::make('test')
->requiresConfirmation(fn () => false)
->modalDescription(function () {
return 'test';
})
)
the modal still pops up the only way i can make it to work is by putting the condition in the modalDescription callback. but i find that weird, why doesn't requiresConfirmation overrule the modalDescription? this does what i want
Action::make('generatePassword')
->modalDescription(function (User $user) {
if (! $user->isAdmin()) {
return 'are you sure?';
}
})
Action::make('generatePassword')
->modalDescription(function (User $user) {
if (! $user->isAdmin()) {
return 'are you sure?';
}
})
which is weird, because the if (! $user->isAdmin()) { logic should be in requiresConfirmation
LeandroFerreira
\Filament\Forms\Components\Actions\Action::make('test')
->requiresConfirmation(false)
->modalDescription('Are you sure you want to do this?')
->modal(false)
->action(function () {})
\Filament\Forms\Components\Actions\Action::make('test')
->requiresConfirmation(false)
->modalDescription('Are you sure you want to do this?')
->modal(false)
->action(function () {})
this?
bernhard
bernhard2w ago
Maybe I am stupid, but this is exactly how it works for me. Lets say the following field:
TextInput::make('zip')
->suffixAction(
\Filament\Forms\Components\Actions\Action::make("xxx")
->requiresConfirmation(fn($record) => $record->id == 105)
->modalDescription("This will be shown if confirmed or if no confirmation is required.")
),
TextInput::make('zip')
->suffixAction(
\Filament\Forms\Components\Actions\Action::make("xxx")
->requiresConfirmation(fn($record) => $record->id == 105)
->modalDescription("This will be shown if confirmed or if no confirmation is required.")
),
On a recor 105 I see a confirmation. When I accept it, I see the "This will" modal When I cancel it, i dont see it
LeandroFerreira
use the same condition here ->modal(false)
rgeraads
rgeraadsOP2w ago
that condition causes no modal in any case
bernhard
bernhard2w ago
On record 200 I dont see the confirmation but the modal "This..."
LeandroFerreira
could you share the whole code?
bernhard
bernhard2w ago
This was just an example. I dont know if you have a record with ID = 105
rgeraads
rgeraadsOP2w ago
Action::make('generatePassword')
->requiresConfirmation(true)
->modalDescription('Are you sure you want to do this?')
->modal(false)
->action(function () {}),
Action::make('generatePassword')
->requiresConfirmation(true)
->modalDescription('Are you sure you want to do this?')
->modal(false)
->action(function () {}),
LeandroFerreira
if requiresConfirmation is true, modal should be true true/true false/false
rgeraads
rgeraadsOP2w ago
requiresConfirmation can be omitted and you'd have the same result, only using modal true/ false requiresConfirmation is ignored even, because this does show a modal
Action::make('generatePassword')
->requiresConfirmation(false)
->modalDescription('Are you sure you want to do this?')
->modal(true)
->action(function () {}),
)
Action::make('generatePassword')
->requiresConfirmation(false)
->modalDescription('Are you sure you want to do this?')
->modal(true)
->action(function () {}),
)
and this doesn't
Action::make('generatePassword')
->requiresConfirmation(true)
->modalDescription('Are you sure you want to do this?')
->modal(false)
->action(function () {}),
)
Action::make('generatePassword')
->requiresConfirmation(true)
->modalDescription('Are you sure you want to do this?')
->modal(false)
->action(function () {}),
)
so what does requiresConfirmation do?
LeandroFerreira
didn't you expect this result?
$admin = true;
\Filament\Forms\Components\Actions\Action::make('test')
->requiresConfirmation($admin)
->modalDescription('Are you sure you want to do this?')
->modal(! $admin)
->action(fn () => dd($admin))
$admin = true;
\Filament\Forms\Components\Actions\Action::make('test')
->requiresConfirmation($admin)
->modalDescription('Are you sure you want to do this?')
->modal(! $admin)
->action(fn () => dd($admin))
rgeraads
rgeraadsOP2w ago
requiresConfirmation doesn’t do anything in that example. It is overruled by modalDescription
LeandroFerreira
admin true - there is no confirmation admin false - requires confirmation ?
rgeraads
rgeraadsOP2w ago
What do you get if you remove requiresConfirmation?
LeandroFerreira
what about this?
$admin = false;
\Filament\Forms\Components\Actions\Action::make('test')
->requiresConfirmation(! $admin)
->modalDescription(! $admin ? 'Are you sure you want to do this?' : null)
->action(fn () => dd($admin))
$admin = false;
\Filament\Forms\Components\Actions\Action::make('test')
->requiresConfirmation(! $admin)
->modalDescription(! $admin ? 'Are you sure you want to do this?' : null)
->action(fn () => dd($admin))
rgeraads
rgeraadsOP2w ago
Yeah that works, I said that above. But even in this example if you remove requiresConfirmation you will get the same result
LeandroFerreira
you mean, we will get a modal without the requiresconfirmation format, right?
rgeraads
rgeraadsOP2w ago
Yes, requiresConfirmation is ignored
josef
josef2w ago
afaik
requiresConfirmation()
requiresConfirmation()
just sets some default modal content for the confirmation dialog, it does not determine whether to show the modal in principle
awcodes
awcodes2w ago
RequiresConfirmation intersects the original action callback and halts it until it is confirmed. It’s typical use case would be on delete actions or actions with forms. Sounds like you might be trying to merge 2 concepts into one. I could be wrong on that though.

Did you find this page helpful?