->requiresConfirmation() on a button on the blade

Guys, is there any way to add the ->requiresConfirmation() to a button in blade?
Solution:
Thanks, I managed to do this: ``` public function deliverAction(): Action {...
Jump to solution
7 Replies
Dennis Koch
Dennis Koch2d ago
You can't use that method – since it's part of the field API – but you could check the source code for the same code that opens a modal and runs code after.
charlie
charlie2d ago
I've done it in one project by calling an existing action
Dennis Koch
Dennis Koch2d ago
Maybe explain more about your "button in Blade". Why don't you use a Filament Action?
charlie
charlie2d ago
If it can help, this works fine when using a custom Livewire component in a resource form:
<x-filament::button
wire:click="mountAction('yourActionName')"
>
Click me
</x-filament::button>
<x-filament::button
wire:click="mountAction('yourActionName')"
>
Click me
</x-filament::button>
You need to have an existing action in the same page:
Action::make('yourActionName')
->requiresConfirmation()
Action::make('yourActionName')
->requiresConfirmation()
Myster
MysterOP2d ago
My button looks like this:
<x-filament::button wire:click="deliver" color="primary" size="sm" class="w-full">
Button
</x-filament::button>
<x-filament::button wire:click="deliver" color="primary" size="sm" class="w-full">
Button
</x-filament::button>
It already calls a function on the custom page, this function changes the state of some data. But I needed it to issue requiresConfirmation when the button is pressed so there are no errors. The button has to be customized like this on the blade.
charlie
charlie2d ago
you could move your logic to an existing action if you are in a resource context OR use livewire native confirmation: https://livewire.laravel.com/docs/wire-confirm
Laravel
wire:confirm | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Solution
Myster
Myster2d ago
Thanks, I managed to do this:
public function deliverAction(): Action
{
return Action::make('')
->label('')
->icon('')
->modalHeading('')
->modalDescription('')
->requiresConfirmation()
->action(function (): void {
$this->deliver();
});
}

Blade:
<div>
{{ $this->deliverAction() }}
</div>
public function deliverAction(): Action
{
return Action::make('')
->label('')
->icon('')
->modalHeading('')
->modalDescription('')
->requiresConfirmation()
->action(function (): void {
$this->deliver();
});
}

Blade:
<div>
{{ $this->deliverAction() }}
</div>

Did you find this page helpful?