Table Action with Custom Form opening new tab

I have a TableAction with a Custom Form that I need to open a view in a new tab. Is this possible? I tried with redirect but it doesn't open it in a new tab.
6 Replies
awcodes
awcodes2y ago
->openUrlInNewTab() assuming you are also using the ->url() method
.robertogarces
.robertogarcesOP2y ago
yes, but if i use url the form modal doesn't work
Action::make('pdf')
->label('PDF')
->form([
DateTimePicker::make('fecha_inicio')
->label('Fecha y hora de entrada')
->displayFormat('d/m/Y H:i')
->withoutSeconds(),
DateTimePicker::make('fecha_hasta')
->label('Fecha y hora de salida')
->displayFormat('d/m/Y H:i')
->withoutSeconds()
->hidden(),
DateTimePicker::make('fecha_desde')
->label('Fecha y hora de entrada')
->displayFormat('d/m/Y H:i')
->withoutSeconds()
->hidden()
])
->url(fn (Servicio $record, array $data) => route('crearPDF', $record, $data))
->openUrlInNewTab(),
Action::make('pdf')
->label('PDF')
->form([
DateTimePicker::make('fecha_inicio')
->label('Fecha y hora de entrada')
->displayFormat('d/m/Y H:i')
->withoutSeconds(),
DateTimePicker::make('fecha_hasta')
->label('Fecha y hora de salida')
->displayFormat('d/m/Y H:i')
->withoutSeconds()
->hidden(),
DateTimePicker::make('fecha_desde')
->label('Fecha y hora de entrada')
->displayFormat('d/m/Y H:i')
->withoutSeconds()
->hidden()
])
->url(fn (Servicio $record, array $data) => route('crearPDF', $record, $data))
->openUrlInNewTab(),
this opens the pdf in a new tab but doesn't fire the modal before
Dennis Koch
Dennis Koch2y ago
I don't think there is an option to open a redirect in a new tab in Livewire
awcodes
awcodes2y ago
Try this:
->action(function ($record, array $data, $action) {
return $action->url(function () use ($record, $data) { return route('crearPDF', $record, $data); })->openUrlInNewTab();
})
->action(function ($record, array $data, $action) {
return $action->url(function () use ($record, $data) { return route('crearPDF', $record, $data); })->openUrlInNewTab();
})
Dennis Koch
Dennis Koch2y ago
If this works, that would require another click, right?
awcodes
awcodes2y ago
i don't know that it does work but the action is just the submit button in the modal right. so there wouldn't be another click yea, doesn't work. 😦 this feels gross to me, but it works with the caveat that the user will have to allow the url to be opened.
->action(function ($livewire, $record, array $data) {
$livewire->dispatchBrowserEvent('create-pdf-' . $record->id, [
'url' => '/pdf?record=' . $record->id . '&fecha_inicio=' . $data['fecha_inicio'],
]);
return null;
})
->extraAttributes(function($record) {
return ['x-on:create-pdf-' . $record->id . '.window' => 'window.open(event.detail.url)'];
}),
->action(function ($livewire, $record, array $data) {
$livewire->dispatchBrowserEvent('create-pdf-' . $record->id, [
'url' => '/pdf?record=' . $record->id . '&fecha_inicio=' . $data['fecha_inicio'],
]);
return null;
})
->extraAttributes(function($record) {
return ['x-on:create-pdf-' . $record->id . '.window' => 'window.open(event.detail.url)'];
}),
Want results from more Discord servers?
Add your server