Hotwire form wizard question

Hello Guys,

I’m in process of making a form wizard using hotwire and stimulus JS.
I’m displaying one field at a time as a question to the user.
My question is what is the best way to save user answers, should I save user answer after each question or should I build a JS object and save it at the end of the wizard?

what are the pros and cons of each approach?

Thank you

I think the answer to this depends on some additional requirements.

  • If someone abandons the wizard part way through, do you want to persist the data?
  • If data validation requires a multiple pages to validate the entire wizard, then you would need to submit all at once.

Other than using hidden forms, you could use redis to temporarily data until the end.

We recently built a stacked wizard that consisted of multiple pages. We first built each page separately. Each controller handled it’s own rendering and data validation. Then, we sprinkled with javascript (turbo-frames and turbo-streams) and combined the wizard to display on a single page. After submitting the first section/form, the section would render the read-only view and move you to the next section below to fill out the next step.

Thanks for your kind reply!

to answer your questions
Yes, I want to persist the data if the user abandons the wizard and when he comes back I want to redirect him to the last step he was on.

the data does not need multiple pages to be validated.

I like your redis suggestion though, I think I should go with this approuch

Best regards