F
Filamentβ€’6mo ago
Vladimir

Wizard ->startOnStep()

IN the documentation i see amazing feature.
Wizard::make([
// ...
])->startOnStep(2)
Wizard::make([
// ...
])->startOnStep(2)
However, i don't know how could i use it. Scenario is that your user is starting long wizard form and abandon it from any reason. A few hours later, or a few days later, he comes back and we want to set him up to continue where he left. In my another app i solved that quite easily by setting user loacl storage with form data, and when he lands on the form again, i pop the modal telling him that we detected existing form data and if he want to proceed. Then simply refill data we have and user proceed from the step he left earlier/ Now, is there a way to set data to local storage during the filling up form wizard, so i can use it to decide on what step user will start?
Solution:
You can achieve saving the form multiple ways. One way would be to use step lifecycle hooks to save the data on each step. https://filamentphp.com/docs/3.x/forms/layout/wizard#step-lifecycle-hooks Then you can get the form state in and serialise it so it can be saved in localstorage. ...
Jump to solution
5 Replies
ChesterS
ChesterSβ€’6mo ago
startOnStep acceps a closure so you can put anything you want there eg
->startOnStep(fn (Get $get) => filled($get('role')) ? 2 : 1)
->startOnStep(fn (Get $get) => filled($get('role')) ? 2 : 1)
In the above example, we start on step 2 if role already has a value (eg if the user has selected a role from a dropdown) You can change it to w/e you want. Is this what you wanted?
Vladimir
Vladimirβ€’6mo ago
Thank you for jumping in. No. What i want is to on every "next" step, save the value of Wizard Step, so when user come tomorrow, to continue the form he proceed with the form on the step he left yesterday, if you know what i mean? πŸ™‚ Ideally i think this can be solved by saving form step and data into the localStorage in browser, and then when user land on page, pul it from storage data and set Wizard to step, something like
->startOnStep(fn () => loaclStorage.step_number)
->startOnStep(fn () => loaclStorage.step_number)
The whole idea is to allow user to cintinue on step he left 1-2-3 days ago.
Solution
ChesterS
ChesterSβ€’6mo ago
You can achieve saving the form multiple ways. One way would be to use step lifecycle hooks to save the data on each step. https://filamentphp.com/docs/3.x/forms/layout/wizard#step-lifecycle-hooks Then you can get the form state in and serialise it so it can be saved in localstorage. When the form loads, you can use ->fill() on the form to load the data from local storage (how you access that data is a different story) In general, I would suggest against using local storage for something like that (for many reasons). Look for a better way to save the form in the database (or something similar that you control). I don't know how complex your form is, but you can create a model for 'incomplete' forms or something similar
ChesterS
ChesterSβ€’6mo ago
It might be simpler than using local storage tbh
Vladimir
Vladimirβ€’6mo ago
This actually is fantastic idea! I did earlier with local storage with vue as the front end and works perfectly, however I see the way now with saving it in the same model with the flag of incomplete and easy to fill the form later! This helped! I kinda needed another perspective, thank you man, much appreciated!