Add custom form field settings for boolean fields.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-17 09:36:07 -04:00
parent a89a237b5c
commit 33239a097b
1 changed files with 41 additions and 20 deletions

View File

@ -1,22 +1,43 @@
{% load widget_tweaks %} {% load widget_tweaks %}
<form role="form" method="post"> <div class="container-fluid">
{% csrf_token %} <form role="form" method="post">
{% for field in form %} {% csrf_token %}
<div class="form-group"> {% for field in form %}
<label for="id_{{ field.name }}">{{ field.label }}</label> <div class="d-none">{{ field|field_type }}</div>
{% if field.errors %} <div class="form-group row">
{{ field|add_class:"form-control is-invalid" }} {% if field|field_type == 'booleanfield' %}
{% else %} <div class="col-sm-1">&nbsp;</div>
{{ field|add_class:"form-control" }} <div class="col-sm-11">
{% endif %} <div class="form-check">
{% if field.help_text %} <label for="id_{{ field.name }}" class="form-check-label">
<p class="help-block"><small>{{ field.help_text }}</small></p> {% if field.errors %}
{% endif %} {{ field|add_class:'form-check-input is-invalid' }}
{% if field.errors %} {% else %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p> {{ field|add_class:'form-check-input' }}
{% endif %} {% endif %}
</div> {{ field.label }}
{% endfor %} </label>
<button type="submit" class="btn btn-primary">Submit</button> </div>
</form> </div>
{% else %}
<label for="id_{{ field.name }}" class="col-sm-1 col-form-label">{{ field.label }}</label>
<div class="col-sm-11">
{% if field.errors %}
{{ field|add_class:'form-control is-invalid' }}
{% else %}
{{ field|add_class:'form-control' }}
{% endif %}
</div>
{% endif %}
{% if field.help_text %}
<p class="help-block"><small>{{ field.help_text }}</small></p>
{% endif %}
{% if field.errors %}
<p class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>