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:
requiresConfirmation is ignored if modalDescription is not null
43 Replies
Can't reproduce. I just added the Action to the
getHeaderActions
array on a Edit-Page:
And I get the confirmation modal.what do you get if you flip it around? requiresConfirmation resulting in false and modalDescription being filled
same
that's wrong, the modal should not be shown
What? There is no modal at all, because there is no modal content
do you get the modal if you try this?
yes
because now you have a modal content
isn't the modal content just placeholder text?
->modalDescription('are you sure you want to do this?')
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 alli want to have a conditional confirmation, and i want to have a customized confirmation message
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 insteadI get the same behaviour if I do this:
yes this is exactly what i did
that's why i think this is a bug
where is the action() method in your code?
where are you using this action?
in my form as a suffixAction on a textInput
and in
protected function getFormActions(): array
use Filament\Forms\Components\Actions\Action;
actually
https://filamentphp.com/docs/3.x/forms/actions#adding-an-affix-action-to-a-fieldI do use that
the example is merely an example
this shows me the confirmation modal
without the modalDescription as well
are you using this in the Panel builder or only in the Form Builder?
custom page or resource?
resource -> form builder
👆 Didn't it work?
i dont want the confirmation to show in some conditions
but it always pops up
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
which is weird, because the
if (! $user->isAdmin()) {
logic should be in requiresConfirmation
this?
Maybe I am stupid, but this is exactly how it works for me. Lets say the following field:
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
use the same condition here
->modal(false)
that condition causes no modal in any case
On record 200 I dont see the confirmation but the modal "This..."
could you share the whole code?
This was just an example. I dont know if you have a record with ID = 105
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
and this doesn't
so what does requiresConfirmation do?
didn't you expect this result?
requiresConfirmation doesn’t do anything in that example. It is overruled by modalDescription
admin true - there is no confirmation
admin false - requires confirmation
?
What do you get if you remove requiresConfirmation?
what about this?
Yeah that works, I said that above. But even in this example if you remove requiresConfirmation you will get the same result
you mean, we will get a modal without the requiresconfirmation format, right?
Yes, requiresConfirmation is ignored
afaik just sets some default modal content for the confirmation dialog, it does not determine whether to show the modal in principle
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.