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