diff --git a/CHANGES.rst b/CHANGES.rst index 580c6ed..b32e169 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Changelog ------ - Fix ``enctype`` attribute setting for WTForms ``MultipleFileField``. +- Fix field class append bug when using ``render_kw={'class': 'my-class'}`` (`#53 `__). 1.2.0 ------ diff --git a/flask_bootstrap/templates/bootstrap/form.html b/flask_bootstrap/templates/bootstrap/form.html index d0c1a6d..8cc2207 100644 --- a/flask_bootstrap/templates/bootstrap/form.html +++ b/flask_bootstrap/templates/bootstrap/form.html @@ -45,7 +45,7 @@ {% call _hz_form_wrap(horizontal_columns, form_type, True, required=required) %}
{% endcall %} @@ -54,12 +54,12 @@ this is just a hack for now, until I can think of something better #}
{%- if form_type == "inline" %} - {{ field.label(class="sr-only")|safe }} + {{ field.label(class="sr-only %s" % field.render_kw.class)|safe }} {% elif form_type == "horizontal" %} {{ field.label(class="form-control-label " + ( - " col-%s-%s" % horizontal_columns[0:2]))|safe }} + " col-%s-%s %s" % (horizontal_columns[0:2], field.render_kw.class)))|safe }} {%- else -%} - {{ field.label(class="form-control-label")|safe }} + {{ field.label(class="form-control-label %s" % field.render_kw.class)|safe }} {% endif %} {% if form_type == 'horizontal' %}
@@ -83,7 +83,7 @@ {# note: same issue as above - should check widget, not field type #} {% call _hz_form_wrap(horizontal_columns, form_type, True, required=required) %} - {{ field(class='btn btn-%s' % button_map.get(field.name, 'secondary'), + {{ field(class='btn btn-%s %s' % (button_map.get(field.name, 'secondary'), field.render_kw.class), **field_kwargs) }} {% endcall %} {%- elif field.type in ['FormField', 'FieldList'] -%} @@ -109,15 +109,15 @@ {{ field.label(class="sr-only")|safe }} {% if field.type == 'FileField' %} {% if field.errors %} - {{ field(class="form-control-file is-invalid", **kwargs)|safe }} + {{ field(class="form-control-file is-invalid %s" % field.render_kw.class, **kwargs)|safe }} {% else %} - {{ field(class="form-control-file", **kwargs)|safe }} + {{ field(class="form-control-file %s" % field.render_kw.class, **kwargs)|safe }} {% endif %} {% else %} {% if field.errors %} - {{ field(class="form-control mb-2 mr-sm-2 mb-sm-0 is-invalid", **kwargs)|safe }} + {{ field(class="form-control mb-2 mr-sm-2 mb-sm-0 is-invalid %s" % field.render_kw.class, **kwargs)|safe }} {% else %} - {{ field(class="form-control mb-2 mr-sm-2 mb-sm-0", **kwargs)|safe }} + {{ field(class="form-control mb-2 mr-sm-2 mb-sm-0 %s" % field.render_kw.class, **kwargs)|safe }} {% endif %} {% endif %} {% elif form_type == "horizontal" %} @@ -125,15 +125,15 @@
{% if field.type == 'FileField' %} {% if field.errors %} - {{ field(class="form-control-file is-invalid", **kwargs)|safe }} + {{ field(class="form-control-file is-invalid %s" % field.render_kw.class, **kwargs)|safe }} {% else %} - {{ field(class="form-control-file", **kwargs)|safe }} + {{ field(class="form-control-file %s" % field.render_kw.class, **kwargs)|safe }} {% endif %} {% else %} {% if field.errors %} - {{ field(class="form-control is-invalid", **kwargs)|safe }} + {{ field(class="form-control is-invalid %s" % field.render_kw.class, **kwargs)|safe }} {% else %} - {{ field(class="form-control", **kwargs)|safe }} + {{ field(class="form-control %s" % field.render_kw.class, **kwargs)|safe }} {% endif %} {% endif %}
@@ -152,15 +152,15 @@ {{ field.label(class="form-control-label")|safe }} {% if field.type == 'FileField' %} {% if field.errors %} - {{ field(class="form-control-file is-invalid", **kwargs)|safe }} + {{ field(class="form-control-file is-invalid %s" % field.render_kw.class, **kwargs)|safe }} {% else %} - {{ field(class="form-control-file", **kwargs)|safe }} + {{ field(class="form-control-file %s" % field.render_kw.class, **kwargs)|safe }} {% endif %} {% else %} {% if field.errors %} - {{ field(class="form-control is-invalid", **kwargs)|safe }} + {{ field(class="form-control is-invalid %s" % field.render_kw.class, **kwargs)|safe }} {% else %} - {{ field(class="form-control", **kwargs)|safe }} + {{ field(class="form-control %s" % field.render_kw.class, **kwargs)|safe }} {% endif %} {% endif %} {%- if field.errors %} diff --git a/test_bootstrap_flask.py b/test_bootstrap_flask.py index 39ea015..c20bd4b 100644 --- a/test_bootstrap_flask.py +++ b/test_bootstrap_flask.py @@ -98,8 +98,8 @@ def test(): response = self.client.get('/field') data = response.get_data(as_text=True) - self.assertIn('