Inline Forms

This commit is contained in:
David Smith 2020-07-13 16:41:06 +01:00
parent fe7a0cf3c5
commit 5a5cece5bd
11 changed files with 31 additions and 33 deletions

View File

@ -1,7 +1,7 @@
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
<div class="checkbox"> <div class="form-check">
<label> <label>
<input type="checkbox" name="{{ field.name }}" value="true" {% if field.value %}checked{% endif %}> <input class="form-check-input{% if field.errors %} is-invalid{% endif %}" type="checkbox" name="{{ field.name }}" value="true" {% if field.value %}checked{% endif %}>
{% if field.label %}{{ field.label }}{% endif %} {% if field.label %}{{ field.label }}{% endif %}
</label> </label>
</div> </div>

View File

@ -1,16 +1,14 @@
{% load rest_framework %} {% load rest_framework %}
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only">{{ field.label }}</label> <label class="sr-only">{{ field.label }}</label>
{% endif %} {% endif %}
{% for key, text in field.choices|items %} {% for key, text in field.choices|items %}
<div class="checkbox"> <div class="form-check {% if style.inline %}form-check-inline {% endif %}">
<label> <input class="form-check-input{% if field.errors %} is-invalid{% endif %}" type="checkbox" name="{{ field.name }}" value="{{ key }}" {% if key|as_string in field.value|as_list_of_strings %}checked{% endif %}>
<input type="checkbox" name="{{ field.name }}" value="{{ key }}" {% if key|as_string in field.value|as_list_of_strings %}checked{% endif %}> <label>{{ text }}</label>
{{ text }}
</label>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -1,9 +1,9 @@
<div class="mb-3"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
</label> </label>
{% endif %} {% endif %}
<p class="form-control-static">Dictionaries are not currently supported in HTML input.</p> <p class="form-text">Dictionaries are not currently supported in HTML input.</p>
</div> </div>

View File

@ -1,6 +1,8 @@
{% load rest_framework %} {% load rest_framework %}
<div class="row row-cols-md-auto g-3 align-items-center">
{% for field in form %} {% for field in form %}
{% if not field.read_only %} {% if not field.read_only %}
{% render_field field style=style %} {% render_field field style=style %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div>

View File

@ -1,9 +1,9 @@
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
</label> </label>
{% endif %} {% endif %}
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value is not None %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}> <input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control{% if field.errors %} is-invalid{% endif %}"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value is not None %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
</div> </div>

View File

@ -1,9 +1,9 @@
<div class="mb-3"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
</label> </label>
{% endif %} {% endif %}
<p class="form-control-static">Lists are not currently supported in HTML input.</p> <p class="form-text">Lists are not currently supported in HTML input.</p>
</div> </div>

View File

@ -1 +1,3 @@
<span>Lists are not currently supported in HTML input.</span> <div class="col-12">
<span class="form-text">Lists are not currently supported in HTML input.</span>
</div>

View File

@ -2,7 +2,7 @@
{% load rest_framework %} {% load rest_framework %}
{% trans "None" as none_choice %} {% trans "None" as none_choice %}
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
@ -10,20 +10,16 @@
{% endif %} {% endif %}
{% if field.allow_null or field.allow_blank %} {% if field.allow_null or field.allow_blank %}
<div class="radio"> <div class="form-check {% if style.inline %}form-check-inline {% endif %}">
<label> <input class="form-check-input{% if field.errors %} is-invalid{% endif %}" type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %}>
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %}> <label>{{ none_choice }}</label>
{{ none_choice }}
</label>
</div> </div>
{% endif %} {% endif %}
{% for key, text in field.choices|items %} {% for key, text in field.choices|items %}
<div class="radio"> <div class="form-check {% if style.inline %}form-check-inline {% endif %}">
<label> <input class="form-check-input{% if field.errors %} is-invalid{% endif %}" type="radio" name="{{ field.name }}" value="{{ key }}" {% if key|as_string == field.value|as_string %}checked{% endif %}>
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key|as_string == field.value|as_string %}checked{% endif %}> <label>{{ text }}</label>
{{ text }}
</label>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -1,13 +1,13 @@
{% load rest_framework %} {% load rest_framework %}
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
</label> </label>
{% endif %} {% endif %}
<select class="form-control" name="{{ field.name }}"> <select class="form-select{% if field.errors %} is-invalid{% endif %}" name="{{ field.name }}">
{% if field.allow_null or field.allow_blank %} {% if field.allow_null or field.allow_blank %}
<option value="" {% if not field.value %}selected{% endif %}>--------</option> <option value="" {% if not field.value %}selected{% endif %}>--------</option>
{% endif %} {% endif %}

View File

@ -2,14 +2,14 @@
{% load rest_framework %} {% load rest_framework %}
{% trans "No items to select." as no_items %} {% trans "No items to select." as no_items %}
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
</label> </label>
{% endif %} {% endif %}
<select multiple {{ field.choices|yesno:",disabled" }} class="form-control" name="{{ field.name }}"> <select multiple {{ field.choices|yesno:",disabled" }} class="form-select{% if field.errors %} is-invalid{% endif %}" name="{{ field.name }}">
{% for select in field.iter_options %} {% for select in field.iter_options %}
{% if select.start_option_group %} {% if select.start_option_group %}
<optgroup label="{{ select.label }}"> <optgroup label="{{ select.label }}">

View File

@ -1,9 +1,9 @@
<div class="mb-3 {% if field.errors %}has-error{% endif %}"> <div class="col-12">
{% if field.label %} {% if field.label %}
<label class="sr-only"> <label class="sr-only">
{{ field.label }} {{ field.label }}
</label> </label>
{% endif %} {% endif %}
<input name="{{ field.name }}" type="text" class="form-control" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %}> <input name="{{ field.name }}" type="text" class="form-control{% if field.errors %} is-invalid{% endif %}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %}>
</div> </div>