How to listen to dispatch events in form?
so i have a button for populating the repeater, basically the button will open a modal and inside a modal there is a livewire filament table. in the bulk action i want to dispatch selected data back to the form.
This is my button
This is my bulk action
Solution:Jump to solution
in the table bulk action i use 2 dispatch
one for passing the data, and the other for closing the modal.
```php
$livewire->dispatch('attach-record', data: $record->select(['id'])->first());...
12 Replies
or is there any other way to pass the data ?
Hmmm..... you can try
$set('../parent_fieldss')
basically traversing with ../../
Did you solve the issue? I 'm interested in the solution
i did
Solution
in the table bulk action i use 2 dispatch
one for passing the data, and the other for closing the modal.
and listen it in the create file
mmhh... very interesting... You put the listener in the create page... interesting.. pages are livewire object... resources are not! Maybe is this my problem!
During the weekend I will try to adapt your solution to my needs and I will let you know.
Thank you for showing the way! (This is the way...cit.)
Dear Wbzy,
the dispatch for data is working like a charm.
What I'm not able to do is closing the modal.
My modal was open in this way:
I don't have any idea how can I close it. I don't know the id or name... or what is needed here:
you need to pass the livewire id to the view like this
and mount it in your table livewire component
I got it!
Now I can close the modal.
I have to thank you for your support.
There is just one problem yet, sorry if I abuse of your patience.
The problem is something I didn't think about in the beginning when I started with this approch and it is the following.
My action is done in this way:
As you can see in ->action I'm setting the value of some fields using what I have received through the dispatch. This is working perfectly if I hit "SAVE" (or somthing similar) in the modal. But if I'm closing the modal programmatically the function in -> action() is never called.
So most probably I have to set the values from here:
But I didn't find a way.
Later I will check into the filament source code to see if there is an hint for doing that.
.
Thank you again
you can set the data after listen it, maybe something like this?
So easy!
I owe you a beer! Or maybe two!
no problem, glad it helps!
I just find a different solution: instead of passing the component_id and modifying the blade file for accepting it, you can do something like this in foundContact()
Didn't know which is the best approach