Use requiresConfirmation on modal form

Hey, I'm searching for a way to use requiresConfirmation with a modal form I'm using the form to use a range to delete models The requiresConfirmation has no effect on the static action I tried replacing the static action with a plain action but I'm struggling to pass the form datas Could you help me figure this out please ?
4 Replies
LeandroFerreira
LeandroFerreira7mo ago
share some code you are trying to do..
skyrowl
skyrowlOP7mo ago
sure
class MassDeleteAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->model(
fn (FullCalendarWidget $livewire) => $livewire->getModel()
);

$this->requiresConfirmation();

$this->form(
fn (FullCalendarWidget $livewire) => [
Forms\Components\Grid::make(6)
->schema([
Forms\Components\DatePicker::make('from')
->displayFormat('D j M Y')
->columnSpan(3)
->native(false)
->required()
->reactive()
->label('Du (inclus)'),
Forms\Components\DatePicker::make('to')
->displayFormat('D j M Y')
->native(false)
->minDate(function (Get $get) {
return $get('from');
})
->columnSpan(3)
->required()
->label('Au (inclus)'),
]),
]
);

$this->after(
fn (FullCalendarWidget $livewire) => $livewire->refreshRecords()
);

$this->cancelParentActions();
}
}
class MassDeleteAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->model(
fn (FullCalendarWidget $livewire) => $livewire->getModel()
);

$this->requiresConfirmation();

$this->form(
fn (FullCalendarWidget $livewire) => [
Forms\Components\Grid::make(6)
->schema([
Forms\Components\DatePicker::make('from')
->displayFormat('D j M Y')
->columnSpan(3)
->native(false)
->required()
->reactive()
->label('Du (inclus)'),
Forms\Components\DatePicker::make('to')
->displayFormat('D j M Y')
->native(false)
->minDate(function (Get $get) {
return $get('from');
})
->columnSpan(3)
->required()
->label('Au (inclus)'),
]),
]
);

$this->after(
fn (FullCalendarWidget $livewire) => $livewire->refreshRecords()
);

$this->cancelParentActions();
}
}
skyrowl
skyrowlOP7mo ago
looks like that's what I'm looking for and chaining is working, tho I just don't know why but it won't pass arguments down to the second action
protected function headerActions(): array
{
return [
MassDeleteAction::make('mass_delete')
->label('Suppression en masse')
->modalHeading('Suppression en masse')
->action(fn (array $data) => $this->replaceMountedAction('fire', $data)),
];
}

public function fireAction(): Action
{
return Action::make('fire')
->requiresConfirmation()
->action(function (array $data) {
dd($data); // Returns []
});
}
protected function headerActions(): array
{
return [
MassDeleteAction::make('mass_delete')
->label('Suppression en masse')
->modalHeading('Suppression en masse')
->action(fn (array $data) => $this->replaceMountedAction('fire', $data)),
];
}

public function fireAction(): Action
{
return Action::make('fire')
->requiresConfirmation()
->action(function (array $data) {
dd($data); // Returns []
});
}
my mistake, arguments var must be named $arguments in the second action, thx a lot @Leandro Ferreira 😄
Want results from more Discord servers?
Add your server