From 61360c2ecab41db5a18d403848c79e416de4229f Mon Sep 17 00:00:00 2001 From: mdanse Date: Sat, 8 Jul 2023 18:10:58 +1000 Subject: [PATCH] Update lib.html to allow for horizontal forms in Bootstrap 4 Use the FLASK_ADMIN_FORM_HORIZONTAL setting to control using vertical (default) or horizontal forms. --- .../templates/bootstrap4/admin/lib.html | 97 ++++++++++--------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/flask_admin/templates/bootstrap4/admin/lib.html b/flask_admin/templates/bootstrap4/admin/lib.html index a4d0c37c9..00e4a977a 100644 --- a/flask_admin/templates/bootstrap4/admin/lib.html +++ b/flask_admin/templates/bootstrap4/admin/lib.html @@ -119,56 +119,61 @@ {% set direct_error = h.is_field_error(field.errors) %} {% set prepend = kwargs.pop('prepend', None) %} {% set append = kwargs.pop('append', None) %} -
- - {% if prepend or append %} -
- {%- if prepend -%} -
- {{ prepend }} -
- {%- endif -%} - {% endif %} - {% if field.widget.input_type == 'checkbox' %} - {% set _class = kwargs.setdefault('class', '') %} - {% elif field.widget.input_type == 'file' %} - {% set _class = kwargs.setdefault('class', 'form-control-file') %} - {% else %} - {% set _class = kwargs.setdefault('class', 'form-control') %} - {% endif %} - {%- if direct_error %} {% set _ = kwargs.update({'class': kwargs['class'] ~ ' is-invalid'}) %} {% endif -%} - {{ field(**kwargs) | safe }} - {%- if append -%} -
- {{ append }} -
- {%- endif -%} - {% if direct_error %} -
-
    - {% for e in field.errors if e is string %} -
  • {{ e }}
  • - {% endfor %} -
-
- {% elif field.description %} - - {{ field.description|safe }} - - {% endif %} - {% if prepend or append %} + {% set form_horizontal = config.get('FLASK_ADMIN_FORM_HORIZONTAL', False) %} +
+ + {% if form_horizontal %} +
+ {% endif %} + {% if prepend or append %} +
+ {%- if prepend -%} +
+ {{ prepend }}
+ {%- endif -%} + {% endif %} + {% if field.widget.input_type == 'checkbox' %} + {% set _class = kwargs.setdefault('class', 'form-control-lg') %} + {% elif field.widget.input_type == 'file' %} + {% set _class = kwargs.setdefault('class', 'form-control-file') %} + {% else %} + {% set _class = kwargs.setdefault('class', 'form-control') %} {% endif %} - {% if caller %} - {{ caller(form, field, direct_error, kwargs) }} + {%- if direct_error %} {% set _ = kwargs.update({'class': kwargs['class'] ~ ' is-invalid'}) %} {% endif -%} + {{ field(**kwargs) | safe }} + {%- if append -%} +
+ {{ append }} +
+ {%- endif -%} + {% if direct_error %} +
+
    + {% for e in field.errors if e is string %} +
  • {{ e }}
  • + {% endfor %} +
+
+ {% elif field.description %} +
{{ field.description|safe }}
{% endif %} + {% if prepend or append %} +
+ {% endif %} + {% if caller %} + {{ caller(form, field, direct_error, kwargs) }} + {% endif %} + {% if form_horizontal %}
+ {% endif %} +
{% endmacro %} {% macro render_header(form, text) %}