title: Flask-WTF form with a variable number of fields (a list of items)
body: <p>I've a form to create a cocktail recipe. It has some common fields like name, description and others, and also a list of ingredients. An ingredient has an ID (foreign-key for a table of ingredients), as the value of a <code>select</code> tag, a name and a <em>quantity</em> numeric field, as user input. At first, in the HTML there is only one field for an ingredient; if the user want to add another ingredient to the recipe, a button 'Add ingredient' create another field, just after the previous one.</p>
  <p>How can I manage this kind of form with WTForms and Flask-WTF, in a Python/Flask backend?
  My problem is: how can I say in the form class &quot;there is this list that must have at least one item (an ingredient), and no maximum&quot; so that I can properly insert the recipe into database?</p>
  <p>Edit:</p>
  <p>This is my 'add new drink' form. There is no 'ingredients' field because that's what I can't do.</p>
  <pre class="lang-py prettyprint-override"><code>class AddDrinkForm(FlaskForm):
      drink_id = HiddenField(&quot;ID&quot;)
      name = StringField(&quot;Name&quot;, validators=[InputRequired(), Length(min=1, max=255)])
      description = TextAreaField(&quot;Description&quot;, validators=[Optional(), Length(min=1, max=512)])
      submit = SubmitField(&quot;Save&quot;)
  </code></pre>
  <p>This is the form on the client-side. There is at least one ingredient field, with a select menu and a textbox to specify it's quantity.
  <a href="https://i.stack.imgur.com/0T0PC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0T0PC.png" alt="enter image description here" /></a></p>
  <p>If I click on &quot;Add ingredient&quot; this happens:
  <a href="https://i.stack.imgur.com/gUTNy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gUTNy.png" alt="enter image description here" /></a></p>
  <p>With JS, I create another field for another ingredient with the same structure. If I click again, it add a new ingredient and so on. The question is the same: how should I structure my (WTF-)form to include this (not predefined) number of ingredients?</p>