Skip to content

Commit

Permalink
Merge pull request #192 from greyli/render-form-row-param
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli authored Jan 12, 2022
2 parents aee7417 + 87a9d6f commit 828503c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
38 changes: 22 additions & 16 deletions docs/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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.

Expand Down
11 changes: 9 additions & 2 deletions flask_bootstrap/templates/bootstrap4/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@
col_map={},
button_map={},
button_style='',
button_size='') %}
button_size='',
form_type='basic',
horizontal_columns=('lg', 2, 10)) %}
<div class="{{ row_class }}">
{% for field in fields %}
{% if field.name in col_map %}
Expand All @@ -308,7 +310,12 @@
{% set col_class = col_class_default %}
{% endif %}
<div class="{{ col_class }}">
{{ 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) }}
</div>
{% endfor %}
</div>
Expand Down
12 changes: 10 additions & 2 deletions flask_bootstrap/templates/bootstrap5/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@
button_map={},
button_style='',
button_size='',
form_group_classes='') %}
form_group_classes='',
form_type='basic',
horizontal_columns=('lg', 2, 10)) %}
<div class="{{ row_class }}">
{% for field in fields %}
{% if field.name in col_map %}
Expand All @@ -286,7 +288,13 @@
{% set col_class = col_class_default %}
{% endif %}
<div class="{{ col_class }}">
{{ 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) }}
</div>
{% endfor %}
</div>
Expand Down

0 comments on commit 828503c

Please sign in to comment.