F
Filament7mo ago
haritz

Open url in modal action

Hello, I am trying to open an url with parameters in a table modal. I want to open a modal, ask the user to write the message and then send it. So far I have the next code but I do not know how to make it work.
->extraModalFooterActions(fn (ActionTable $action): array => [
$action->makeModalSubmitAction('send')
->label('Send')
->icon('heroicon-o-paper-airplane')
->color('success'),
])
->action(function (array $data, array $arguments, $record, $action): void {
if ($data['message']) {
$customer = Customer::find($record->customer_id);
$message = $data['message'];
$url = 'https://api.whatsapp.com/send?phone=' . $customer->number . '&text=' . urlencode($message);
$action->url($url);
$action->openUrlInNewTab();
}
})
->extraModalFooterActions(fn (ActionTable $action): array => [
$action->makeModalSubmitAction('send')
->label('Send')
->icon('heroicon-o-paper-airplane')
->color('success'),
])
->action(function (array $data, array $arguments, $record, $action): void {
if ($data['message']) {
$customer = Customer::find($record->customer_id);
$message = $data['message'];
$url = 'https://api.whatsapp.com/send?phone=' . $customer->number . '&text=' . urlencode($message);
$action->url($url);
$action->openUrlInNewTab();
}
})
Solution:
Try this: ```php Tables\Actions\Action::make('test') ->form([ TextInput::make('name')->reactive(),...
Jump to solution
9 Replies
haritz
haritzOP7mo ago
Any idea how I can do this?
Patrick Boivin
Patrick Boivin7mo ago
It's not completely clear what you're trying to do... Can you maybe share a screenshot?
haritz
haritzOP7mo ago
When I click the action, open the next modal. When I click the send button, I want to open an url with the data of the from. I get the data but I need to open theurl. Hope I explained well
No description
haritz
haritzOP7mo ago
No description
Patrick Boivin
Patrick Boivin7mo ago
One way to open a URL would be with a link. You can change the Send button into a link.
haritz
haritzOP7mo ago
But how could I get the message contetn? The send button is rendered once the modal is open
Patrick Boivin
Patrick Boivin7mo ago
If your fields are reactive() or lazy(), the button will re-render.
Solution
Patrick Boivin
Patrick Boivin7mo ago
Try this:
Tables\Actions\Action::make('test')
->form([
TextInput::make('name')->reactive(),
])
->modalSubmitAction(function ($action, $livewire) {
$action->url('https://www.example.com/' . ($livewire->mountedTableActionsData[0]['name'] ?? ''));
}),
Tables\Actions\Action::make('test')
->form([
TextInput::make('name')->reactive(),
])
->modalSubmitAction(function ($action, $livewire) {
$action->url('https://www.example.com/' . ($livewire->mountedTableActionsData[0]['name'] ?? ''));
}),
haritz
haritzOP7mo ago
Worked perfectly. Thank you very much.
Want results from more Discord servers?
Add your server