How can I get current active form tab in a EditResource page?
I use the tabs layout for a form https://filamentphp.com/docs/3.x/forms/layout/tabs, I want to get current active tab so I can use it inside the getRedirectUrl method for the EditResource.
2 Replies
I was also struggling and had to use the method below.
It seems a bit manual, but hopefully it helps you
First:
in form:
Then define function :
Then:
in mount or in submit function call getActiveTabVHelper
Document: https://filamentphp.com/docs/3.x/forms/layout/tabs#persisting-the-current-tab-in-the-urls-query-string
Thank you, not exactly same use case, but inspired to use this to get the tab inside redirect url method:
protected function getRedirectUrl(): ?string
{
$queryString = parse_url(request()->server('HTTP_REFERER'))['query'] ?? null;
if ($queryString) {
parse_str($queryString ?? '', $queryParams);
$tab = $queryParams['tab'];
}
if ($tab == '-services-tab') {
return $this->getResource()::getUrl('edit', ['record' => $this->record, 'tab' => '-services-tab']);
}
return null;
}