Skip to content

Commit

Permalink
Fix WTForms field description not showing for BooleanField
Browse files Browse the repository at this point in the history
  • Loading branch information
VV-YY committed Apr 21, 2020
1 parent 21fe081 commit 309489c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Changelog
1.3.0
------

- Fix ``enctype`` attribute setting for WTForms ``MultipleFileField``.
- Fix field class append bug when using ``render_kw={'class': 'my-class'}`` (`#53 <https://github.com/greyli/bootstrap-flask/issues/53>`__).
- Fix ``enctype`` attribute setting for WTForms ``MultipleFileField`` (`Flask-Bootstrap #198<https://github.com/mbr/flask-bootstrap/issues/198>`__).
- Fix WTForms field class append bug when using ``render_kw={'class': 'my-class'}`` (`#53 <https://github.com/greyli/bootstrap-flask/issues/53>`__).
- Fix WTForms field description not showing for ``BooleanField`` (`Flask-Bootstrap #197<https://github.com/mbr/flask-bootstrap/issues/197>`__).

1.2.0
------
Expand Down
5 changes: 5 additions & 0 deletions flask_bootstrap/templates/bootstrap/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<label class="form-check-label">
{{ field(class_="form-check-input %s" % field.render_kw.class)|safe }} {{ field.label.text|safe }}
</label>
{%- if field.description -%}
{% call _hz_form_wrap(horizontal_columns, form_type, required=required) %}
<small class="form-text text-muted">{{ field.description|safe }}</small>
{% endcall %}
{%- endif %}
</div>
{% endcall %}
{%- elif field.type == 'RadioField' -%}
Expand Down
21 changes: 20 additions & 1 deletion test_bootstrap_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def multi():
self.assertIn('multipart/form-data', data)


# test WTForm fields for render_form and render_field
# test render_kw class for WTForms field
def test_form_render_kw_class(self):
class TestForm(FlaskForm):
submit = SubmitField(render_kw={'class': 'my-awesome-class'})
Expand All @@ -379,3 +379,22 @@ def render_kw():
data = response.get_data(as_text=True)
self.assertIn('my-awesome-class', data)
self.assertIn('btn', data)


# test WTForm field description for BooleanField
def test_form_description_for_booleanfield(self):
class TestForm(FlaskForm):
remember = BooleanField('Remember me', description='Just check this')

@self.app.route('/description')
def description():
form = TestForm()
return render_template_string('''
{% from 'bootstrap/form.html' import render_form %}
{{ render_form(form) }}
''', form=form)

response = self.client.get('/description')
data = response.get_data(as_text=True)
self.assertIn('Remember me', data)
self.assertIn('<small class="form-text text-muted">Just check this</small>', data)

0 comments on commit 309489c

Please sign in to comment.