Simple form:
class AdjustPWMForm(Form):
dutyCycle = IntegerField('dutycycle')
#dutyCycle = IntegerField('dutycycle', default=44)
View function:
def adjust():
user = g.user
form = AdjustPWMForm()
form.dutyCycle.data = 55
if form.validate_on_submit():
dutyCycle = form.dutyCycle.data
print('result %s', dutyCycle)
return redirect(url_for('statusPage'))
return render_template('adjust.html', title='Adjust PWM', user=user, form=form)
When the form is submitted, the result is always 55, regardless of what has been entered. If I comment out the 55 line, and uncomment the line with the default=44, the form works properly, but I really need to be able to set the prepopulate value (it will be retrieved from the database).
It seems like I'm missing something really obvious, but I've hunted around and can't figure it out.
I found the section in change_username useful in wtforms which leads me to:
def adjust():
user = g.user
form = AdjustPWMForm(dutyCycle=55)
if form.validate_on_submit():
dutyCycle = form.dutyCycle.data
return redirect(url_for('statusPage'))
return render_template('adjust.html', title='Adjust PWM', user=user, form=form)
Is that the best way to accomplish this?