Trigger a modal action from within Repeater extraItemActions
Hello,
I have something like this:
any idea if this is possible?
Repeater::make('reports_samples_ids')
->columnSpanFull()
->extraItemActions([
Action::make('generare_raport_grupa')
->icon(Heroicon::Envelope)
->action(function (array $arguments, $state, $context, Repeater $component, Order $itemRecord): void {
$itemData = $component->getItemState($arguments['item']);
$pdfExists = self::findPdf($itemRecord->id, $arguments['item']);
// here i want to check if pdfExists and if so, i want to open a modal action with submit and cance footer actions
self::confirmReportGeneration($arguments['item'], $itemRecord->id);
}),
])
Repeater::make('reports_samples_ids')
->columnSpanFull()
->extraItemActions([
Action::make('generare_raport_grupa')
->icon(Heroicon::Envelope)
->action(function (array $arguments, $state, $context, Repeater $component, Order $itemRecord): void {
$itemData = $component->getItemState($arguments['item']);
$pdfExists = self::findPdf($itemRecord->id, $arguments['item']);
// here i want to check if pdfExists and if so, i want to open a modal action with submit and cance footer actions
self::confirmReportGeneration($arguments['item'], $itemRecord->id);
}),
])
5 Replies
I've tried something like using notification, but when i click :
when i click on "Generate new report" action in the notification it shows this error
if ($pdfExists) {
// PDF exists -> show confirmation modal
Notification::make()
->title('Raport exists already')
->body('Report exists already, do you want a new one?')
->warning()
->actions([
Action::make('generateNew')
->label('Generate new report')
->action(fn() => self::generateAndDownloadReport($itemRecord->id, $arguments['item'])),
])
->send();
} else {
self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
}
if ($pdfExists) {
// PDF exists -> show confirmation modal
Notification::make()
->title('Raport exists already')
->body('Report exists already, do you want a new one?')
->warning()
->actions([
Action::make('generateNew')
->label('Generate new report')
->action(fn() => self::generateAndDownloadReport($itemRecord->id, $arguments['item'])),
])
->send();
} else {
self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
}
Unable to call component method. Public method [mountAction] not found on component
Unable to call component method. Public method [mountAction] not found on component
Look at the
$livewire->replaceMountedAction()
function
You'll need to figure out the exact arguments to pass to it depending on where your second modal action is defined@ralphjsmit you refer for case when i'm trying to trigger another action ?
i think there's a but with actions on repeater in v4 🙁
Yes
ended up doing something like this
->action(function ($action, $arguments, Repeater $component, Order $itemRecord) {
if(isset($arguments['actual']) && $arguments['actual']) {
return self::downloadGeneratedReport($itemRecord->id, $arguments['item']);
}
return self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
})
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['actual' => true])->label('Download actual report'),
]),
->action(function ($action, $arguments, Repeater $component, Order $itemRecord) {
if(isset($arguments['actual']) && $arguments['actual']) {
return self::downloadGeneratedReport($itemRecord->id, $arguments['item']);
}
return self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
})
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['actual' => true])->label('Download actual report'),
]),