Adjust form layout for better BS4 integration.

This commit is contained in:
Christopher Charbonneau Wells 2017-10-31 15:15:02 -04:00
parent 8c274ce765
commit 9c0989d22b
2 changed files with 33 additions and 20 deletions

View File

@ -5,3 +5,8 @@
right: 0;
left: auto; // Reset the default from `.dropdown-menu`
}
// BB form fields do not follow typical BS4 style that enables this display.
.invalid-feedback {
display: block;
}

View File

@ -3,12 +3,26 @@
<div class="container-fluid">
<form role="form" method="post">
{% csrf_token %}
{% if form.non_field_errors %}
{% for error in form.non_field_errors %}
<div class="alert alert-danger" role="alert">
<strong>Error:</strong> {{ error }}
</div>
{% endfor %}
{% elif form.errors %}
<div class="alert alert-danger" role="alert">
<strong>Error:</strong> Some fields have errors. See below for details.
</div>
{% endif %}
{% 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 d-none d-sm-block">&nbsp;</div>
<div class="col-sm-11">
<label for="id_{{ field.name }}" class="col-sm-1 col-form-label">
{% if field|field_type != "booleanfield" %}
{{ field.label }}
{% endif %}
</label>
<div class="col-sm-11">
{% if field|field_type == "booleanfield" %}
<div class="form-check">
<label for="id_{{ field.name }}" class="form-check-label">
{% if field.errors %}
@ -19,10 +33,7 @@
{{ field.label }}
</label>
</div>
</div>
{% elif field|field_type == "datetimefield" or field|field_type == "datefield" %}
<label for="id_{{ field.name }}" class="col-sm-1 col-form-label">{{ field.label }}</label>
<div class="col-sm-11">
{% elif field|field_type == "datetimefield" or field|field_type == "datefield" %}
<div class="form-group">
<div class="input-group date" id="datetimepicker_{{ field.name }}" data-target-input="nearest">
<div class="input-group-addon" data-target="#datetimepicker_{{ field.name }}" data-toggle="datetimepicker">
@ -35,23 +46,20 @@
{% endif %}
</div>
</div>
</div>
{% else %}
<label for="id_{{ field.name }}" class="col-sm-1 col-form-label">{{ field.label }}</label>
<div class="col-sm-11">
{% else %}
{% 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 %}
{% endif %}
{% if field.help_text %}
<div class="help-block"><small>{{ field.help_text }}</small></div>
{% endif %}
{% if field.errors %}
<div class="invalid-feedback">{% for error in field.errors %}{{ error }}{% endfor %}</div>
{% endif %}
</div>
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Submit</button>