F
Filament10mo ago
QCTFW

Confirmation Alert Before Creating a Record

Hello, I want to add a confirmation alert before creating a record in Order model. I already tried this code in CreateOrder class but still does not working, the form got submitted without a confirmation alert. Do I missed something? How to solve this?
<?php

namespace App\Filament\Resources\OrderResource\Pages;

use App\Filament\Resources\OrderResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\CreateRecord;

class CreateOrder extends CreateRecord
{
protected static string $resource = OrderResource::class;

protected function getCreateFormAction(): Action
{
return parent::getCreateFormAction()
->requiresConfirmation();
}
}
<?php

namespace App\Filament\Resources\OrderResource\Pages;

use App\Filament\Resources\OrderResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\CreateRecord;

class CreateOrder extends CreateRecord
{
protected static string $resource = OrderResource::class;

protected function getCreateFormAction(): Action
{
return parent::getCreateFormAction()
->requiresConfirmation();
}
}
5 Replies
Patrick Boivin
Patrick Boivin10mo ago
I'm not sure, but here's a snippet from a v2 project that works for me. Hope it can be useful:
protected function getSaveFormAction(): Action
{
return Action::make('save')
->label(__('filament::resources/pages/edit-record.form.actions.save.label'))
->action(fn($livewire) => $livewire->save())
->requiresConfirmation();
}
protected function getSaveFormAction(): Action
{
return Action::make('save')
->label(__('filament::resources/pages/edit-record.form.actions.save.label'))
->action(fn($livewire) => $livewire->save())
->requiresConfirmation();
}
Replacing the Action entirely
QCTFW
QCTFW10mo ago
I've already tried this. In v3, getSaveFormAction() does not exists so I change the method to getCreateFormAction() and change Action::make('save') to Action::make('create') but the confirmation alert still does not pop up. This is my current code. I used the parent CreateRecord class as a reference.
protected function getCreateFormAction(): Action
{
return Action::make('create')
->icon('heroicon-s-shopping-cart')
->label('Create an Order')
->submit('create')
->requiresConfirmation()
->modalHeading('Confirm the Order')
->modalDescription('Do you confirm that the order is correct?')
->modalSubmitActionLabel('Confirm')
->keyBindings(['mod+s']);
}
protected function getCreateFormAction(): Action
{
return Action::make('create')
->icon('heroicon-s-shopping-cart')
->label('Create an Order')
->submit('create')
->requiresConfirmation()
->modalHeading('Confirm the Order')
->modalDescription('Do you confirm that the order is correct?')
->modalSubmitActionLabel('Confirm')
->keyBindings(['mod+s']);
}
Patrick Boivin
Patrick Boivin10mo ago
Yes, so getSaveFormAction() is for Edit pages and getCreateFormAction() for Create pages. I think you need to remove the ->submit() for the confirmation modal to work If I remember correctly, that's why I'm using ->action() instead in my example
QCTFW
QCTFW10mo ago
I changed ->submit('create') to ->action(fn($livewire) => $livewire->save()), but the save() function does not exist.
No description
QCTFW
QCTFW10mo ago
Okay, I changed the code to $livewire->create() and now the code is working. Thank you so much for helping me. Solved Code
protected function getCreateFormAction(): Action
{
return Action::make('create')
->icon('heroicon-s-shopping-cart')
->label('Create an Order')
->action(fn (CreateOrder $livewire) => $livewire->create())
->requiresConfirmation()
->modalHeading('Confirm the Order')
->modalDescription('Do you confirm that the order is correct?')
->modalSubmitActionLabel('Confirm')
->keyBindings(['mod+s']);
}
protected function getCreateFormAction(): Action
{
return Action::make('create')
->icon('heroicon-s-shopping-cart')
->label('Create an Order')
->action(fn (CreateOrder $livewire) => $livewire->create())
->requiresConfirmation()
->modalHeading('Confirm the Order')
->modalDescription('Do you confirm that the order is correct?')
->modalSubmitActionLabel('Confirm')
->keyBindings(['mod+s']);
}