I'm generating a html form with wtforms like this:
<div class="control-group">
{% for subfield in form.time_offset %}
<label class="radio">
{{ subfield }}
{{ subfield.label }}
</label>
{% endfor %}
</div>
My form class is like this:
class SN4639(Form):
time_offset = RadioField(u'Label', choices=[
('2', u'Check when Daylight saving has begun, UTC+02:00'),
('1', u'Check when Daylight saving has stopped, UTC+01:00')],
default=2, validators=[Required()])
When I now open the edit form, I get via SQL the value 1 or 2 - how can I preset the specifiy radiobutton?
WTForms is a flexible forms validation and rendering library for Python web development. It can work with whatever web framework and template engine you choose. It supports data validation, CSRF protection, internationalization (I18N), and more.
String field theory (SFT) is a formalism in string theory in which the dynamics of relativistic strings is reformulated in the language of quantum field theory.
If I understand your question properly, you want to have the form render with a pre-selected choice (rather than returning a default choice if no value is submitted to the form)...
What you can do is construct the form while setting the pre-selected value:
myform = SN4639(time_offset='2')
And then pass myform
off to your template to be rendered.
default=2 needs to be of type string, not int:
class SN4639(Form):
time_offset = RadioField(u'Label', choices=[
('2', u'Check when Daylight saving has begun, UTC+02:00'),
('1', u'Check when Daylight saving has stopped, UTC+01:00')],
default='2', validators=[Required()])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With