Pre-populating a BooleanField as checked (WTForms)
A BooleanField defined like:
checkbox = BooleanField('title',
default=True,
render_kw ={'checked':''})
snahor's answer helped after much searching (+1). The google seems weak on this question. I found I needed
<div class="form-group">
{{adminForm.is_admin.label}}
{{adminForm.is_admin(checked=True, class_="form-control")}}
</div>
<div class="form-group">
{{adminForm.is_admin.label}}
{{adminForm.is_admin(checked=False, class_="form-control")}}
</div>
which I have utilised as
<div class="form-group">
{{adminForm.is_admin.label}}
{{adminForm.is_admin(checked=user.is_admin, class_="form-control")}}
</div>
If you have an object you can use it to populate your form like form = QuestionForm(obj=my_obj)
. If you only want to set the active attribute use form = QuestionForm(active=True)
.