From 87a9d6fcfde5a3b58ea3c909d64126cab65176e9 Mon Sep 17 00:00:00 2001 From: Grey Li Date: Wed, 12 Jan 2022 18:13:11 +0800 Subject: [PATCH] Add form_type and horizontal_columns to render_form_row --- docs/macros.rst | 38 +++++++++++-------- .../templates/bootstrap4/form.html | 11 +++++- .../templates/bootstrap5/form.html | 12 +++++- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/docs/macros.rst b/docs/macros.rst index 8c90ea4b..d9ae6bb8 100644 --- a/docs/macros.rst +++ b/docs/macros.rst @@ -109,12 +109,12 @@ API ~~~~ .. py:function:: render_field(field,\ - form_type="basic",\ + form_type='basic',\ horizontal_columns=('lg', 2, 10),\ - button_style="",\ - button_size="",\ + button_style='',\ + button_size='',\ button_map={},\ - form_group_classes="") + form_group_classes='') :param field: The form field (attribute) to render. :param form_type: One of ``basic``, ``inline`` or ``horizontal``. See the @@ -152,21 +152,21 @@ API ~~~~ .. py:function:: render_form(form,\ - action="",\ - method="post",\ + action='',\ + method='post',\ extra_classes=None,\ - role="form",\ - form_type="basic",\ + role='form',\ + form_type='basic',\ horizontal_columns=('lg', 2, 10),\ enctype=None,\ - button_style="",\ - button_size="",\ + button_style='',\ + button_size='',\ button_map={},\ - id="",\ + id='',\ novalidate=False,\ render_kw={},\ - form_group_classes="",\ - form_inline_classes="",) + form_group_classes='',\ + form_inline_classes='',) :param form: The form to output. :param action: The URL to receive form data. @@ -260,10 +260,12 @@ API row_class='row/form-row',\ col_class_default='col',\ col_map={},\ - button_style="",\ - button_size="",\ + button_style='',\ + button_size='',\ button_map={},\ - form_group_classes="") + form_group_classes='',\ + form_type='basic',\ + horizontal_columns=('lg', 2, 10)) :param fields: An iterable of fields to render in a row. :param row_class: Class to apply to the div intended to represent the row, like ``form-row`` (Bootstrap 4) @@ -282,6 +284,10 @@ API :param form_group_classes: Bootstrap 5 only (``bootstrap5/form.html``). You can use this parameter to change the form group classes, it will read the config ``BOOTSTRAP_FORM_GROUP_CLASSES`` first (the default value is ``mb-3``) + :param form_type: One of ``basic``, ``inline`` or ``horizontal``. See the Bootstrap docs for details on different + form layouts. + :param horizontal_columns: When using the horizontal layout, layout forms like this. Must be a 3-tuple of + ``(column-type, left-column-size, right-column-size)``. .. tip:: See :ref:`button_customization` to learn how to customize form buttons. diff --git a/flask_bootstrap/templates/bootstrap4/form.html b/flask_bootstrap/templates/bootstrap4/form.html index b6691fed..8295aedb 100644 --- a/flask_bootstrap/templates/bootstrap4/form.html +++ b/flask_bootstrap/templates/bootstrap4/form.html @@ -299,7 +299,9 @@ col_map={}, button_map={}, button_style='', - button_size='') %} + button_size='', + form_type='basic', + horizontal_columns=('lg', 2, 10)) %}
{% for field in fields %} {% if field.name in col_map %} @@ -308,7 +310,12 @@ {% set col_class = col_class_default %} {% endif %}
- {{ render_field(field, button_map=button_map, button_style=button_style, button_size=button_size) }} + {{ render_field(field, + button_map=button_map, + button_style=button_style, + button_size=button_size, + form_type=form_type, + horizontal_columns=horizontal_columns) }}
{% endfor %}
diff --git a/flask_bootstrap/templates/bootstrap5/form.html b/flask_bootstrap/templates/bootstrap5/form.html index 54d4bfc4..feba1310 100644 --- a/flask_bootstrap/templates/bootstrap5/form.html +++ b/flask_bootstrap/templates/bootstrap5/form.html @@ -277,7 +277,9 @@ button_map={}, button_style='', button_size='', - form_group_classes='') %} + form_group_classes='', + form_type='basic', + horizontal_columns=('lg', 2, 10)) %}
{% for field in fields %} {% if field.name in col_map %} @@ -286,7 +288,13 @@ {% set col_class = col_class_default %} {% endif %}
- {{ render_field(field, button_map=button_map, button_style=button_style, button_size=button_size, form_group_classes=form_group_classes) }} + {{ render_field(field, + button_map=button_map, + button_style=button_style, + button_size=button_size, + form_group_classes=form_group_classes, + form_type=form_type, + horizontal_columns=horizontal_columns) }}
{% endfor %}