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 %}
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{% if field.errors %}
{{ field|add_class:"form-control is-invalid" }}
{% else %}
{{ field|add_class:"form-control" }}
{% 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 class="container-fluid">
<form role="form" method="post">
{% csrf_token %}
{% for field in form %}
<div class="d-none">{{ field|field_type }}</div>
<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 %}
{{ field|add_class:'form-check-input is-invalid' }}
{% else %}
{{ 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 %}
{% 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>