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="checkbox">
<div class="col-12">
<div class="form-check">
<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 %}
</label>
</div>

View File

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

View File

@ -1,9 +1,9 @@
<div class="mb-3">
<div class="col-12">
{% if field.label %}
<label class="sr-only">
{{ field.label }}
</label>
{% 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>

View File

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

View File

@ -1,9 +1,9 @@
<div class="mb-3">
<div class="col-12">
{% if field.label %}
<label class="sr-only">
{{ field.label }}
</label>
{% 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>

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

View File

@ -1,13 +1,13 @@
{% load rest_framework %}
<div class="mb-3 {% if field.errors %}has-error{% endif %}">
<div class="col-12">
{% if field.label %}
<label class="sr-only">
{{ field.label }}
</label>
{% 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 %}
<option value="" {% if not field.value %}selected{% endif %}>--------</option>
{% endif %}

View File

@ -2,14 +2,14 @@
{% load rest_framework %}
{% 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 %}
<label class="sr-only">
{{ field.label }}
</label>
{% 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 %}
{% if select.start_option_group %}
<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 %}
<label class="sr-only">
{{ field.label }}
</label>
{% 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>