Last active
October 26, 2019 00:31
-
-
Save eon01/7cee29d3b754866cd3baa828a6cfdade to your computer and use it in GitHub Desktop.
Django bootstrap includable file for forms with better checkboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load widget_tweaks %} | |
{% for hidden_field in form.hidden_fields %} | |
{{ hidden_field }} | |
{% endfor %} | |
{% if form.non_field_errors %} | |
<div class="alert alert-danger" role="alert"> | |
{% for error in form.non_field_errors %} | |
{{ error }} | |
{% endfor %} | |
</div> | |
{% endif %} | |
{% for field in form.visible_fields %} | |
<div class="form-group"> | |
{% if field.field.widget.input_type != "checkbox" %} | |
{{ field.label_tag }} | |
{% endif %} | |
{% if form.is_bound %} | |
{% if field.errors %} | |
{% render_field field class="form-control is-invalid" %} | |
{% for error in field.errors %} | |
<div class="invalid-feedback"> | |
{{ error }} | |
</div> | |
{% endfor %} | |
{% else %} | |
{% render_field field class="form-control is-valid" %} | |
{% endif %} | |
{% else %} | |
{% if field.field.widget.input_type != "checkbox" %} | |
{% render_field field class="form-control" %} | |
{% else %} | |
{% render_field field class="" %} {{ field.label_tag }} | |
{% endif %} | |
{% endif %} | |
{% if field.help_text %} | |
<small class="form-text text-muted">{{ field.help_text }}</small> | |
{% endif %} | |
</div> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment