1

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:

  1. Create a form with ALL of your potential fields
  2. Create another form referencing the first Form via the FieldList function
  3. In Jinja2 somehow render
  4. 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?

1
  • This looks like a duplicate of the above question - if it doesn't answer your question in its entirety, just edit your question and ping me here by @mentioning me in the comments and I'll vote to re-open. Welcome to Stack Overflow! Commented Nov 5, 2015 at 5:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.