diff --git a/crispy_bootstrap5/templates/bootstrap5/field.html b/crispy_bootstrap5/templates/bootstrap5/field.html index 8312e9b..bcf471a 100644 --- a/crispy_bootstrap5/templates/bootstrap5/field.html +++ b/crispy_bootstrap5/templates/bootstrap5/field.html @@ -3,13 +3,13 @@ {% if field.is_hidden %} {{ field }} {% else %} - {% if field|is_checkbox and tag != "td" %} + {% if field|is_checkbox and crispy_tag != "td" %}
{% if label_class %}
{% endif %} {% endif %} - <{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="mb-3{% if field|is_checkbox and form_show_labels %} form-check{% else %}{% if 'form-horizontal' in form_class %} row{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}"> + <{% if crispy_tag %}{{ crispy_tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="mb-3{% if field|is_checkbox and form_show_labels %} form-check{% else %}{% if 'form-horizontal' in form_class %} row{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}"> {% if field.label and not field|is_checkbox and form_show_labels %}
{% endif %} {% endif %} {% endif %} - - {% if field|is_checkbox and tag != "td" %} + + {% if field|is_checkbox and crispy_tag != "td" %} {% if label_class %}
{% endif %} diff --git a/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html b/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html index 097ebb3..e1b6a0a 100644 --- a/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html +++ b/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html @@ -33,7 +33,7 @@ {% for field in formset.empty_form %} - {% include 'bootstrap5/field.html' with tag="td" form_show_labels=False %} + {% include 'bootstrap5/field.html' with crispy_tag="td" form_show_labels=False %} {% endfor %} @@ -44,7 +44,7 @@ {% for field in form %} - {% include 'bootstrap5/field.html' with tag="td" form_show_labels=False %} + {% include 'bootstrap5/field.html' with crispy_tag="td" form_show_labels=False %} {% endfor %} {% endfor %} diff --git a/tests/test_layout.py b/tests/test_layout.py index fc2f551..928b0ed 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -688,3 +688,19 @@ def test_help_text_no_escape(): else: expected = "help_text_escape.html" assert parse_form(form) == parse_expected(expected) + + +def test_tag_context(): + SampleFormSet = formset_factory(SampleForm, extra=3) + formset = SampleFormSet() + formset.helper = FormHelper() + context = { + "form": formset, + "tag": "User defined tag in context", + } + + response = render( + request=None, template_name="crispy_render_template.html", context=context + ) + + assert response.content.count(b"User defined tag in context") == 0