General question on how those working with Flask and WTForms handle dynamic form creation normally done in javascript I did see some of the dynamic form examples in the WTForms documentation but this seems to focus on iterating on back end data to present a dynamic number of fields. Here is what I am wondering how to achieve:
- Simple form -- name,address,city,state,zip. Typically I see a javascript that has a + sign that dynamically adds a set of fields for each person you want to fill out fields for. Then when done you submit. This is all done client-side.
@Sean Viera Now I understand the advantages of server-side form creation/validation but not sure how I can achieve a similar affect. With javascript I look at the DOM event for the + being clicked and then render another set of fields. Not sure how I can achieve similar with WTForms?
Is this possible? Or is there another approach (write the form in javascript and then validate the fields on the server-side when they are submitted..)
Thank you for pointing me to the other article -- it does help, but I could use a little more basic description as I think the poster was a few steps ahead of me.
So - it appears I have to use FieldList. This is my basic understanding but I think I can use a little bit more specific guidance if it wouldn't be too much trouble:
- Create a form with ALL of your potential fields
- Create another form referencing the first Form via the FieldList function
- In Jinja2 somehow render
- On the client side write a script that iterates through the form based on user input
I'm a bit confused on 3/4. Is it possible to post a simplified pseudo-code example?