Handling multiple forms, but one at a time
I changed my app's main workflow from using a customised Wizard to building my own component.
The form schema is determined dynamically, based on the current step.
The
nextStep
action should save the current step and move on to the next.
The problem however is, it uses the cached form, resulting in the wrong (old) form being rendered.
(This does not occur when I switch tabs using setStep
. I don't understand why.)
Any advise on how to handle this?Solution:Jump to solution
I'm not sure but I think you would need to call
$this->form->fill( ... )
at the start of every step... If I understand correctly, all steps share the same state path?8 Replies
An additional problem I'm having, is that a
Repeater
field isn't properly loaded if it's not loaded on the initial step. If I change the initial $currentStep
to the one holding the Repeater
, the current items are shown. If I start on any other step, and use setStep
to navigate to it, simple input fields are shown just fine, but the Repeater
is empty.
This surely has to do with the Livewire / Filament lifecycle, but I wouldn't know how to fix this. Any help is appreciated.
Same with accessors. They are only properly parsed on the initial step. I guess in mount()
the form of the initial step is parsed and any accessors and relations are resolved. If I swap the form later, the form data isn't parsed anew. Can I refresh this somehow?Solution
I'm not sure but I think you would need to call
$this->form->fill( ... )
at the start of every step... If I understand correctly, all steps share the same state path?I remember trying something like this, and messing up the lifecycle even more, where the displayed form was one click behind the selected tab.
But...
This does seem to do the trick!
Thanks a bunch!
Nice! Not sure if I'm missing something but I suspect
$this->request
can cause issues eventually... just curious, where does it come from?Ah.. sry about that. That used to be
$this->getRecord()
, which I got from InteractsWithRecord
. But since I only have to work with a \App\Models\Request
I changed it to get autocomplete.lol, I thought this was related to
request()
😄Yea, I understand the confusion. Thanks again!
I've encountered the problem again, where the form stays the same when I switch steps. I also found a solution, so I'm just adding this to help others that might have the same issue.
The problem comes up whenever you interact with the form before changing the current step. E.g. updating the record:
The cause is that the first time, the form is cached.
The solution is to rebuild the form cache after changing the current step: