F
Filamentβ€’2y ago
rabol

getFormSchema is called on every 'next' in a wizard

Hi it looks like the getFormSchema is called every time you press next in a wizard. First I saw that it was taking a very long time when pressing the 'next', so I started to investigate Here is a simple wizard that shows the error:
13 Replies
rabol
rabolOPβ€’2y ago
rabol
rabolOPβ€’2y ago
First time the component is loaded, the wizard shows, then when pressing 'Next' you will get errors blade view for the wizard looks like this:
<div>
{{ $this->form }}
</div>
<div>
{{ $this->form }}
</div>
toeknee
toekneeβ€’2y ago
So the next does cause a refresh as standard Livewire as there could be changes etc. The problem from what I can see is you are passing it into a php method within the component. You should be calling the Wizard as a field inside the getFormSchema as the page variables are reset on livewire changes if they are not livewire named.
rabol
rabolOPβ€’2y ago
?? I'm trying to avoid that all controls are rebuild everytime you hit next
toeknee
toekneeβ€’2y ago
that goes against livewire, it's exactly what livewire does, as we get the next set of fields for the next step.. as far as I am aware, you cannot adjust this as the Wizard follows the principle of these approach.
rabol
rabolOPβ€’2y ago
sure It would be okay to rebuild for a spcific step, but that is not the case
toeknee
toekneeβ€’2y ago
So the way livewire works is, it sends a request to the server for every change. You are changing the step, so it passes the data back and then back again.
rabol
rabolOPβ€’2y ago
yes, but it keeps values in between e.g. if I assign a private or public property a value it 's not lost during the life time of the component with the wizard the values seems to be lost
toeknee
toekneeβ€’2y ago
That to me appears to be how you have built the component. $this->wzControl is being reset by the livewire component. move the buildMyWizard to the getForm schema method.
rabol
rabolOPβ€’2y ago
no πŸ™‚ The whole point is that I would like to avoid rebuiling 200 controls every time
toeknee
toekneeβ€’2y ago
Ok, then I'm done trying to help! Have a good day πŸ™‚
rabol
rabolOPβ€’2y ago
moving the method does not change the fact that getformschema is called multiple times But that is not normal of livewire component to reset values on a action
toeknee
toekneeβ€’2y ago
It is when they do not exists in the form. You have declared wzControl in the loading of the component, but it doesn't exist within the request because it's not part of the form which is the container over the wizard, so it is dropped.
Want results from more Discord servers?
Add your server