F
Filament16mo ago
Yuut4

Open a specific Modal

I want to open the specific modal when redirect to other page
39 Replies
Yuut4
Yuut4OP16mo ago
I liked that when redirecting to a page it opened right away in the specific site I'm doing it this way
->url(function($record){
$payment = PaymentMap::where('partner_id', $record->partner_id)->where('plan_id', $record->plan_id)->get()->toArray();
$paymentId = $payment[0]['id'];
return "javascript:window.open('" . route('filament.resources.partners.view', [$record->partner_id, 'activeRelationManager' => 4, /*Open specific modal*/ ]) . "', '_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
}),
->url(function($record){
$payment = PaymentMap::where('partner_id', $record->partner_id)->where('plan_id', $record->plan_id)->get()->toArray();
$paymentId = $payment[0]['id'];
return "javascript:window.open('" . route('filament.resources.partners.view', [$record->partner_id, 'activeRelationManager' => 4, /*Open specific modal*/ ]) . "', '_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
}),
Is it possible to open the modal from here?
JibayMcs
JibayMcs16mo ago
If it's only a modal, redirect with a route param example.com/test?open=modal-id And anywhere you want in JS, read the URL param to dispatch an open modal event from Liwewire, I don't remember the exact function but something like $dispach('open-modal', ['id' => "your modal id from url param"])
Yuut4
Yuut4OP16mo ago
will try it out
JibayMcs
JibayMcs16mo ago
Let me find the right function
Yuut4
Yuut4OP16mo ago
dispathBrowserEvent if I'm not in error?
JibayMcs
JibayMcs16mo ago
Laravel
Events | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
JibayMcs
JibayMcs16mo ago
$dispatch('show-post-modal', { id: {{ $post->id }} })
$dispatch('show-post-modal', { id: {{ $post->id }} })
Yuut4
Yuut4OP16mo ago
but isn't that just for the blade?
JibayMcs
JibayMcs16mo ago
Yep, sorry, let me find the filament version
Yuut4
Yuut4OP16mo ago
->actions([
Tables\Actions\ViewAction::make()
->url(function($record){
$payment = PaymentMap::where('partner_id', $record->partner_id)->where('plan_id', $record->plan_id)->get()->toArray();
$paymentId = $payment[0]['id'];
return "javascript:window.open('" . route('filament.resources.partners.view', [$record->partner_id, 'activeRelationManager' => 4, /*Open specific modal*/ ]) . "', '_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
}),
->actions([
Tables\Actions\ViewAction::make()
->url(function($record){
$payment = PaymentMap::where('partner_id', $record->partner_id)->where('plan_id', $record->plan_id)->get()->toArray();
$paymentId = $payment[0]['id'];
return "javascript:window.open('" . route('filament.resources.partners.view', [$record->partner_id, 'activeRelationManager' => 4, /*Open specific modal*/ ]) . "', '_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
}),
this is my code for example, here I redirect to the page where the partners are located for the payment list, I just don't know how to open the specific modal that I want when I click to see the payment on the current page.
JibayMcs
JibayMcs16mo ago
Currently writting a sample code for you 😉
Yuut4
Yuut4OP16mo ago
thx I was thinking of something like this but it doesn't work
$livewire->dispatchBrowserEvent('open-modal', ['id' => $paymentId])
$livewire->dispatchBrowserEvent('open-modal', ['id' => $paymentId])
JibayMcs
JibayMcs16mo ago
Yeah, there are changes between v2/v3 of filament and livewire
Yuut4
Yuut4OP16mo ago
I'm currently using v2 still
JibayMcs
JibayMcs16mo ago
ohhh didn't see the tag on your help post
Yuut4
Yuut4OP16mo ago
I didn't put ? for a moment I thought I had forgotten
JibayMcs
JibayMcs16mo ago
I can't help you since I don't have any project in V2 BUT you have a good starting point here: I'm not sure about the return I maybe forgot some parenthesis 😄
->actions([
Tables\Actions\ViewAction::make()
->url(function($record){
$payment = PaymentMap::where('partner_id', $record->partner_id)->where('plan_id', $record->plan_id)->get()->toArray();
$paymentId = $payment[0]['id'];
return route('filament.resources.partners.view', [$record->partner_id, 'activeRelationManager' => 4, 'modal' => 'modal-payment']);
}),
->actions([
Tables\Actions\ViewAction::make()
->url(function($record){
$payment = PaymentMap::where('partner_id', $record->partner_id)->where('plan_id', $record->plan_id)->get()->toArray();
$paymentId = $payment[0]['id'];
return route('filament.resources.partners.view', [$record->partner_id, 'activeRelationManager' => 4, 'modal' => 'modal-payment']);
}),
<script>
const urlParams = new URLSearchParams(window.location.search);
let modalToOpen = urlParams.get('modal'); // modal-payment

if (modalToOpen) {
// Livewiwre function to open modal or something else
$livewire->dispatchBrowserEvent('open-modal', ['id' => modalToOpen])
}
</script>
<script>
const urlParams = new URLSearchParams(window.location.search);
let modalToOpen = urlParams.get('modal'); // modal-payment

if (modalToOpen) {
// Livewiwre function to open modal or something else
$livewire->dispatchBrowserEvent('open-modal', ['id' => modalToOpen])
}
</script>
Yuut4
Yuut4OP16mo ago
I'll try but where do I put the script part in the resource?
JibayMcs
JibayMcs16mo ago
register it in a custom js file that you load using Filament::registerScripts() in your AppServiceProvider
Yuut4
Yuut4OP16mo ago
ok, I never did that thanks, I never had the need either
JibayMcs
JibayMcs16mo ago
Or override the $view of your Edit[...] inside your App/Filament/Resources/YOUR_RESOURCE/Pages/Edit[YOUR RESOURCE]
Yuut4
Yuut4OP16mo ago
ok, when i have some results i will post here unsuccessfully
Tables\Actions\ViewAction::make()
->url(function ($record, $livewire) {
$payment = PaymentMap::where('partner_id', $record->partner_id)
->where('plan_id', $record->plan_id)
->get()
->toArray();
$paymentId = $payment[0]['id'];
$relationManager = 4; // activate relationManager
//URL for relationManager
$url = route('filament.resources.partners.view', [
$record->partner_id,
'activeRelationManager' => $relationManager,
], $paymentId);
// open URL in a new window
return "javascript:window.open('$url','_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
})
Tables\Actions\ViewAction::make()
->url(function ($record, $livewire) {
$payment = PaymentMap::where('partner_id', $record->partner_id)
->where('plan_id', $record->plan_id)
->get()
->toArray();
$paymentId = $payment[0]['id'];
$relationManager = 4; // activate relationManager
//URL for relationManager
$url = route('filament.resources.partners.view', [
$record->partner_id,
'activeRelationManager' => $relationManager,
], $paymentId);
// open URL in a new window
return "javascript:window.open('$url','_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
})
@Dan Harrin Do you have any tips, I've tried some things but without success, or is it possible?
Patrick Boivin
Patrick Boivin16mo ago
@Duarte Barbosa please read the #✅┊rules and don't tag maintainers who are not part of the conversation
Yuut4
Yuut4OP16mo ago
my bad just waiting for someone to give a tip hopping *
Patrick Boivin
Patrick Boivin16mo ago
It looks like JibayMcs gave you a lot of helpful tips already. What's not working for you?
Yuut4
Yuut4OP16mo ago
basically when i do the redirection to the page with the relation manager, i want to open it in the register in question, and i tried to do the JibayMcs tip but i didn't succeed, i don't know if i missed something?
Yuut4
Yuut4OP16mo ago
I wish I could do something like this, but I still haven't figured out how to open the specific modal
Patrick Boivin
Patrick Boivin16mo ago
This is more complicated in v2... In v3 it's easier to trigger table actions. Do you really need the modal though? Can you instead redirect to a simple Edit page?
Yuut4
Yuut4OP16mo ago
the problem is that this action is performed in relation manager. in v3 I can do this more easily, I can even upgrade, over the weekend I will test it separately, and see how it goes any v3 link that I can base myself on?
Dan Harrin
Dan Harrin16mo ago
i dont know how v3 would be easier tbh maybe patrick knows something i dont all I know is that in Jibay's <script>, he writes PHP. so thats def not gonna work.
Yuut4
Yuut4OP16mo ago
sorry bth i hadn't read all the rules sorry for the tag I was hoping you knew something, my bad
Dan Harrin
Dan Harrin16mo ago
why not just use a normal resource with a page instead of redirecting to a relation manager as patrick said
Yuut4
Yuut4OP16mo ago
I'm going to put this option on the table in the next daily, I hope they accept it xD just a question, can i just make a normal edit page or do i have to make a cutom/resource ?
Dan Harrin
Dan Harrin16mo ago
normal edit page in a resource
Yuut4
Yuut4OP16mo ago
ok thx hope they don't mind. Thank you for your help. Thank you for your help
Patrick Boivin
Patrick Boivin16mo ago
I was referring to this from memory : https://github.com/filamentphp/filament/discussions/7007#discussioncomment-6459024 But the context here is different...
GitHub
call table action after the previous has run · filamentphp filament...
Hello! When a table action is run, is it possible to automatically call another one? Example: after the admin has assigned the element to himself (table action #1), open it for viewing (custom moda...
Dan Harrin
Dan Harrin16mo ago
thats opening one modal after another has finished on the same LW component
Patrick Boivin
Patrick Boivin16mo ago
Yes, distorted memory 😄
Yuut4
Yuut4OP14mo ago
thank you all, you already helped me a lot and removed my doubts, thank you very much So I know it's been a long time since I posted, but I ended up finding a way that I already did about a month ago, but I just had time to stop by here now. basically in relation manager as it is a simple resource, it uses mountTableAction to open the modal so in the main resource I made a url like this

Tables\Actions\ViewAction::make()
->url(function ($record) {
$payment = PaymentMap::where('partner_id', $record->partner_id)
->where('plan_id', $record->plan_id)
->get()
->toArray();
$paymentId = $payment[0]['id'];
$relationManager = 5;
// Gerar a URL para o relationManager com os dados do modal como um parâmetro de consulta
$url = route('filament.resources.partners.view', [
$record->partner_id,
'activeRelationManager' => $relationManager,
'openPayment' => true,
'paymentId' => $paymentId
], $paymentId);
// Abra a URL em uma nova janela
return "javascript:window.open('$url','_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
})

Tables\Actions\ViewAction::make()
->url(function ($record) {
$payment = PaymentMap::where('partner_id', $record->partner_id)
->where('plan_id', $record->plan_id)
->get()
->toArray();
$paymentId = $payment[0]['id'];
$relationManager = 5;
// Gerar a URL para o relationManager com os dados do modal como um parâmetro de consulta
$url = route('filament.resources.partners.view', [
$record->partner_id,
'activeRelationManager' => $relationManager,
'openPayment' => true,
'paymentId' => $paymentId
], $paymentId);
// Abra a URL em uma nova janela
return "javascript:window.open('$url','_blank','location=yes,height=5000,width=900,scrollbars=yes,status=yes')";
})
and in relation manager something like this
protected $queryString = ['openPayment', 'paymentId'];

public $openPayment;
public $paymentId;
//public $isLoading = false;


public function checkOpenModals()
{
if ($this->openPayment) {
//$this->isLoading = true;
$this->mountTableAction('pagamento', $this->paymentId);
}
}
protected $queryString = ['openPayment', 'paymentId'];

public $openPayment;
public $paymentId;
//public $isLoading = false;


public function checkOpenModals()
{
if ($this->openPayment) {
//$this->isLoading = true;
$this->mountTableAction('pagamento', $this->paymentId);
}
}
And that's all if I haven't forgotten anything, it's been a while since I did this, but I remembered that I had opened help here so I came to leave my results. As I said, I forgot to specify something xD in this part:
$this->mountTableAction('pagamento', $this->paymentId);
$this->mountTableAction('pagamento', $this->paymentId);
the 'pagamento' must be the same name given in the action
Tables\Actions\EditAction::make('pagamento')
Tables\Actions\EditAction::make('pagamento')
And now I think I haven't forgotten anything I hope this helps xD
Want results from more Discord servers?
Add your server