title: I'm trying to create drop down lists in flask using wtforms but my form won't validate for some reason, can someone tell me why?
body: <p>The lists look just the way I intended them to, with all the right options, but when I hit the submit('Add Movement') button, it doesn't get validated(it doesn't enter the <code>if form.validate_on_submit()</code> code block). It used to get validated before I added the SelectField so I'm inclined to think I did something wrong there.</p>
  <pre><code>@app.route('/movements', methods=['GET','POST'])
  def movements():
      form = MovementForm()
      if form.validate_on_submit():
          product = Product.query.filter_by(id=form.product.data).first()
          from_location = Location.query.filter_by(id=form.from_location.data).first()
          to_location = Location.query.filter_by(id=form.to_location.data).first()
          m = Movement(product = product.name, from_location = from_location.name, to_location = to_location.name, quantity = form.quantity.data)
          db.session.add(m)
          db.session.commit()
          movements = Movement.query.all()
          products = Product.query.all()
          locations = Location.query.all()
          return render_template('movements.html', movements=movements, products=products, locations=locations, form=form)
      
      form.product.choices = [(product.id,product.name) for product in Product.query.all()]
      form.from_location.choices = [(location.id,location.name) for location in Location.query.all()]
      form.to_location.choices = [(location.id,location.name) for location in Location.query.all()]
      movements = Movement.query.all()
      products = Product.query.all()
      locations = Location.query.all()
      return render_template('movements.html', movements=movements, products=products, locations=locations, form=form)
  </code></pre>
  <p>This is my model for the Movement table:</p>
  <pre><code>class Movement(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
      product = db.Column(db.String(50), nullable=False)
      from_location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
      from_location = db.Column(db.String(50))
      to_location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
      to_location = db.Column(db.String(50))
      quantity = db.Column(db.Integer, nullable=False)
      timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
  </code></pre>
  <p>And this is the form:</p>
  <pre><code>class MovementForm(FlaskForm):
      product = SelectField(&quot;Product&quot;, choices = [])
      from_location = SelectField(&quot;From Location&quot;, choices = [])
      to_location = SelectField(&quot;To Location&quot;, choices = [])
      quantity = StringField(&quot;Quantity&quot;, validators=[DataRequired()])
      add_movement = SubmitField(&quot;Add Movement&quot;)
  </code></pre>