Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoided adding tag to context. #160

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crispy_bootstrap5/templates/bootstrap5/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions to name improvements welcomed!

<div class="mb-3{% if 'form-horizontal' in form_class %} row{% endif %}">
{% if label_class %}
<div class="{% for offset in bootstrap_checkbox_offsets %}{{ offset|slice:"7:14" }}{{ offset|slice:"4:7" }}{{ offset|slice:"14:16" }} {% endfor %}{{ field_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 %}
<label {% if field.id_for_label %}for="{{ field.id_for_label }}"{% endif %} class="{% if 'form-horizontal' in form_class %}col-form-label{% else %}form-label{% endif %}{% if label_class %} {{ label_class }}{% endif %}{% if field.field.required %} requiredField{% endif %}">
{{ field.label }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
Expand Down Expand Up @@ -58,8 +58,8 @@
{% if field_class %}</div>{% endif %}
{% endif %}
{% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% if field|is_checkbox and tag != "td" %}
</{% if crispy_tag %}{{ crispy_tag }}{% else %}div{% endif %}>
{% if field|is_checkbox and crispy_tag != "td" %}
{% if label_class %}
</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tbody>
<tr class="d-none empty-form">
{% 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 %}
</tr>

Expand All @@ -44,7 +44,7 @@

<tr>
{% 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 %}
</tr>
{% endfor %}
Expand Down
16 changes: 16 additions & 0 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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