Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic forms from variable length elements: wtforms
    text
    copied!<p>I'm using wtforms, and I need to create a something that will generate a form definition based off information in a database; dynamic form creation. I'm getting a sense of what needs to be done and I've just started. I can create forms and use them with wtforms/flask but defining forms from data that will vary slightly from form to form is currently beyond my current skill level.</p> <p>Has anyone done this and have some input to offer? Somewhat a vague question, no actual code yet. I haven't found any examples, but it is not impossible to do.</p> <pre><code>mass of variable data to be used in a form --&gt; wtforms ---&gt; form on webpage </code></pre> <p>EDIT: </p> <p>So, a 'for example' we can use surveys. A survey consists of several SQLAlcehmy models. A survey is a model with any number of associated questions models(questions belong to surveys and it gets complicated for say, multiple choice questions). To simplify let's use simple json/dict pseudo code for:</p> <pre><code>{survey:"Number One", questions:{ question:{type:truefalse, field:"Is this true or false"}, question:{type:truefalse, field:"Is this true or false"}, question:{type:text, field:"Place your X here"} } } {survey:"Number Two", questions:{ question:{type:text, field:"Answer the question"}, question:{type:truefalse, field:"Is this true or false"}, question:{type:text, field:"Place your email address here"} } } </code></pre> <p>Imagine instead of this, several hundred of varying lengths with 5+ field types. How to use WTForms to manage forms for this, or do I even need to use wtforms? I can define static forms as I need them, but not dynamically, yet.</p> <p>As an aside I've done something like this in rails with simpleform but as I'm working in Python atm (on something different, I'm using the survey thing as an example, but the question/field/answer thing abstracts across a many types of inputs I've needed).</p> <p>So yes it is possible I'll need to build some sort of factory, doing it will take me some time e.g.:</p> <p><a href="http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html" rel="nofollow">http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html</a></p> <p><a href="https://groups.google.com/forum/?fromgroups=#!topic/wtforms/cJl3aqzZieA" rel="nofollow">https://groups.google.com/forum/?fromgroups=#!topic/wtforms/cJl3aqzZieA</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload