Building big forms with Phoenix and Elixir

Hi,

I just have a general question about the best practices or any suggestions that any one has about this.

I am developing a Phoenix Liveview app which has a large set of forms for users to complete. It’s a form wizard with step by step questionnaires.

My question is, as there are around 110 questions, what is the best way to maintain this?
Is it a good practice to hardcode these form questions in the code?
Or use maybe a toml file to define these questions and then read it and render it on startup or anything else? Have to keep in mind that these questions might need copyright changes from time to time as well

Any ideas, suggestions are welcome!

Who is defining the questions and how often will they change? This would significantly affect my personal decision.

If business/non-dev users are going to be changing questions, then you want to build with that in mind. You don’t want a developer to have to be involved just to change the wording of a question slightly.

Questions are defined by the business team, there is a possibility the wording of these questions can change fairly often

Generation of forms at runtime is certainly the way to go here. I would start with something simple, like defining them as an attribute in your liveview and scale as I see it fit, having a toml file seems to be an overkill at this stage, as you can always implement it later if needed.

Recently @PJUllrich wrote an article on building dynamic forms with JSON Schema that I would definitely recommend reading– Build dynamic Forms with JSON Schemas

4 Likes

The above is good advice. The other thing I’d add from experience: save the original prompt with the response so that you can refer later to the actual question someone answered, instead of whatever the current version is.

2 Likes