fblaser
fblaser
FFilament
Created by fblaser on 1/22/2024 in #❓┊help
Select option is "0" after creating an entry through Select::make(...)->createOptionForm(...)
No description
7 replies
FFilament
Created by fblaser on 8/2/2023 in #❓┊help
Table action to open url in new tab (asynchronous)
Hi, In my app, I have a ressource that represents servers, with a table action that allows the user to login to this server's control panel through a specially crafted url. I want the url to be opened in a new browser/tab/window. The url is generated through an API that is quite slow. Generating the url for each server in a table is therefore unpractical. This is therefore not a solution:
Action::make('login')->url(function ($record) { return $record->loginUrl()})->openUrlInNewTab();
Action::make('login')->url(function ($record) { return $record->loginUrl()})->openUrlInNewTab();
In filament v2, I had resorted to a dirty trick: - Create a custom action in the Resources/ServerResource/ListServer.php. This action generates the url and emits/dispatch a livewire event "openinnewtab" with the url as parameter - Add a global livewire listener through a small js file included on all pages:
Livewire.on('openInNewTab', url => {
window.open(url, '_blank');
})
Livewire.on('openInNewTab', url => {
window.open(url, '_blank');
})
This worked well, but didn't look good. After upgrading to v3, I had to change the way the file is loaded (now using the FilamentAsset facade), and now the listener throws the error in the browser: [Error] ReferenceError: Can't find variable: Livewire This is probably due to a change in which the files are loaded, but it triggers me to find a better way of doing the whole thing. Has anyone any idea on how to have Filament call $record->loginUrl() asynchronously? Thanks heaps,
6 replies