Dispatching Event after Action
Hi guys,
I added a
PriceAssistantAction
class to my application which is used at a specific tab in my ContractResource
while editing a contract. The action itself is working perfectly fine, I just noticed one issue:
When I call $livewire->dispatch('$refresh')
in after()
, the application does not refresh the user interface.25 Replies
Any ideas? 🙂
Not sure, but try
protected $listeners = ['myRefresh' => '$refresh'];
And then dispatch myRefresh
instead of $refresh
$refresh
is working in other places of the application. :/
My current assumption is that $livewire->dispatch('$refresh')
is accessing another Livewire componentwere this working for v2?
https://laravel-livewire.com/docs/2.x/actions#magic-actions
if not mistaken I stumbled to this not long ago in v3, this doesn't seem to be supported anymore, as it is not documented in v3
If you
dd($livewire)
, do you get the expected result? (I'm guessing the Page class)
Good point, it's possible... I'm using it only on a v2 project atmcan't be sure thou, because in the v3 project that i upgraded is not fully tested yet
it seems to be working
i think i recalled it,
$listeners
is not documented in v3, but still supported, the example you shown is working and I'm using it
the issue I had is in v3 doc it wasnt clear how we should trigger $refresh
as the doc is focused on using php attributes #[On]
I never worked with v2, so I can't say tbh
Yes, same for me.
so is your question answered?
dd($livewire)
is returning the correct component. :/
Well, not really. 😅 I still don't know how to refresh the UI since it's not documented anywhere.
$refresh
is also not mentioned in the upgrade guide of Livewire itself
can you try this?
Sure, one moment.
It did not refresh. 😅
ok now I recall x2 what was the issue LOL
the $refresh doesn't seems to be supported anymore, hence not documented, not sure why not mentioned in upgrade guide, maybe you should submit a discussion at livewire repo
so the for this i workaround in my app in this way
don't quote me if it breaking changes in future 😂
$refresh
is working in other places of the same application.
I'll just finish my current thing and I'll show you another example where it's working 🙂added as todo for me to check everywhere in my app LOL
e.g.
this is in
RoomsRelationManager.php
After I attach a room the page is refreshed, let me provide a screencast
You can see the issue and the working example in one video:
"Saisonassistent" is not refresh the page after submitting, but added a room via the relation manager is refreshing.alexander.gaal
TechSmith Screencast
2023-10-12_18-35-30
World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
and this $livewire is the page or the relation manager?
Good question, let me check
so that's different from the actions 🤔
isn't
dispatch
dispatching the event through the whole application? 🤔yes it is
i think i have an answer for this
the form are filled in
mount
and this is only called once for the component, hence it is not refreshed when you dispatch $refresh
what you are seeing refreshed are form schema, not the content
thus your tabs are refreshed
so my question will be, is there any console errors in your browser? should the fields in the new tabs contains data and is it filled correctly? and is the form submittable? can you try on this after the RM dispatched $refresh
and without reloading your browserI‘ll check that tomorrow. I‘m out for today 💭
The form is not submittable, FYI.
so I've to find another solution :/
Did you ever find a solution? Having the exact same issue.
nvm, I solved it here: https://discord.com/channels/883083792112300104/1220475763711676496/1220760210340057119