Having to click action button twice for changes to take place
I have this Button and on click I want to change pdf template
Actions\Action::make('test_smthng')
->label('Change PDF preview')
->action(fn () => $this->selectedView = 'pdf-templates.layout.pdf-preview-default')
and this ViewFIeld that's showing the custom template
protected function getTemplateSection(): Component
{
return Section::make('PDF Preview')
->schema([
Grid::make(1)
->schema([
])->columnSpan(1),
Grid::make()
->schema([
ViewField::make('preview.default')
->columnSpan(2)
->visible()
->view($this->selectedView)
For some reason when I first click on button it doesn't render the selectedView, but when I click again it does. Any ideas?
I tried dispatching refresh on action $this->dispatch('refresh'); and even directly with setting ID on viewfield, but it doesn't work.5 Replies
In network tab both clicks also look identical with request/response:

Sounds like the action hasn't filled or updated it
Note that passing to $this in Livewire means it is delayed, this is why we tend to user $set & $get closures
not sure how to make this work with $set and $get, view() method can't take closure as parameter
I found one thing that works, basically add:
protected $listeners = ['myRefresh' => '$refresh'];
and add in action $this->dispatch('myRefresh');
That works, basically the component isn't refreshing into the DOM when you manually set the parameters in the php class so the refresh makes sense
Ty, one day in future you are getting donation so you have a nice dinner on me for all your help :D!