Improve form style
This commit is contained in:
parent
804b2b38e0
commit
221dbb196e
5 changed files with 77 additions and 62 deletions
|
@ -17,7 +17,7 @@ repos:
|
||||||
rev: v1.23.3
|
rev: v1.23.3
|
||||||
hooks:
|
hooks:
|
||||||
- id: djlint-django
|
- id: djlint-django
|
||||||
args: ["--reformat"]
|
args: ["--reformat", "--lint", "--quiet"]
|
||||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
rev: "v3.0.0-alpha.6"
|
rev: "v3.0.0-alpha.6"
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
@ -6,24 +6,44 @@ form ul.errorlist {
|
||||||
}
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
> table > tbody > tr > th {
|
max-width: 32rem;
|
||||||
background: var(--bg-01);
|
display: grid;
|
||||||
border-right: 1px solid var(--gray);
|
grid-gap: var(--gap);
|
||||||
|
|
||||||
|
p.field {
|
||||||
|
display: grid;
|
||||||
|
grid-auto-rows: min-content;
|
||||||
|
border: 1px solid var(--gray);
|
||||||
|
padding: 0.5rem;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&:has(> input, > select, > textarea) > label {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
line-height: 0.8rem;
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
tbody :is(input, select, textarea) {
|
|
||||||
|
> input,
|
||||||
|
> select,
|
||||||
|
> textarea {
|
||||||
font: inherit;
|
font: inherit;
|
||||||
|
line-height: initial;
|
||||||
border: none;
|
border: none;
|
||||||
background: transparent;
|
border-bottom: 1px solid var(--gray);
|
||||||
width: 100%;
|
background: none;
|
||||||
height: 100%;
|
z-index: 1;
|
||||||
line-height: 1.5;
|
|
||||||
}
|
&[name="value"] {
|
||||||
input[type="checkbox"] {
|
font-size: 1.5rem;
|
||||||
width: initial;
|
|
||||||
}
|
|
||||||
tfoot {
|
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
background: var(--bg-01);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
table.file-input {
|
table.file-input {
|
||||||
tr {
|
tr {
|
||||||
|
@ -42,10 +62,18 @@ table.file-input {
|
||||||
}
|
}
|
||||||
|
|
||||||
.buttons {
|
.buttons {
|
||||||
|
display: grid;
|
||||||
|
grid-auto-columns: min-content;
|
||||||
|
grid-gap: var(--gap);
|
||||||
|
align-items: baseline;
|
||||||
|
|
||||||
|
& > * {
|
||||||
|
grid-row: 1;
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
font: inherit;
|
font: inherit;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
margin-left: var(--gap);
|
|
||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
padding: 0 var(--gap);
|
padding: 0 var(--gap);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -56,13 +84,16 @@ table.file-input {
|
||||||
&[type="submit"] {
|
&[type="submit"] {
|
||||||
border: 0.1rem solid var(--green);
|
border: 0.1rem solid var(--green);
|
||||||
background: var(--green-1);
|
background: var(--green-1);
|
||||||
|
grid-column: 1;
|
||||||
}
|
}
|
||||||
&[type="reset"] {
|
&[type="reset"] {
|
||||||
border: 0.1rem solid var(--red);
|
border: 0.1rem solid var(--red);
|
||||||
background: var(--red-1);
|
background: var(--red-1);
|
||||||
|
grid-column: 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a.del {
|
a.del {
|
||||||
color: var(--red);
|
color: var(--red);
|
||||||
|
grid-column: 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,29 +2,18 @@
|
||||||
{% load main_extras %}
|
{% load main_extras %}
|
||||||
{% block fields %}
|
{% block fields %}
|
||||||
{% if form.non_field_errors %}
|
{% if form.non_field_errors %}
|
||||||
<ul class='errorlist'>
|
<ul class="errorlist">
|
||||||
{% for error in form.non_field_errors %}<li>{{ error }}</li>{% endfor %}
|
{% for error in form.non_field_errors %}<li>{{ error }}</li>{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
{% if field.errors %}
|
{% if field.errors %}<p class="error">{{ field.errors }}</p>{% endif %}
|
||||||
<tr>
|
<p class="field">
|
||||||
<td colspan="2">{{ field.errors }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
<tr>
|
|
||||||
<th class="l">
|
|
||||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
</th>
|
{{ field }}
|
||||||
<td>{{ field }}</td>
|
</p>
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
<div class="buttons">
|
||||||
<tfoot>
|
|
||||||
<tr class="buttons">
|
|
||||||
<td colspan="2">
|
|
||||||
{% block buttons %}
|
{% block buttons %}
|
||||||
{% if not form.instance|adding %}
|
{% if not form.instance|adding %}
|
||||||
<a class="del" href="{{ form.instance.get_delete_url }}">{% translate "Delete" %}</a>
|
<a class="del" href="{{ form.instance.get_delete_url }}">{% translate "Delete" %}</a>
|
||||||
|
@ -35,9 +24,6 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="submit" value="{% translate "Save" %}">
|
<input type="submit" value="{% translate "Save" %}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock buttons %}
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
{% endblock fields %}
|
||||||
</tfoot>
|
|
||||||
</table>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
|
@ -62,5 +62,8 @@ class DatalistInput(TextInput):
|
||||||
|
|
||||||
def get_context(self, *args):
|
def get_context(self, *args):
|
||||||
context = super().get_context(*args)
|
context = super().get_context(*args)
|
||||||
|
name = context["widget"]["name"]
|
||||||
|
context["widget"]["attrs"]["list"] = f"{name}-list"
|
||||||
|
context["widget"]["attrs"]["autocomplete"] = "off"
|
||||||
context["widget"]["options"] = self.options
|
context["widget"]["options"] = self.options
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
<input autocomplete="off"
|
{% include "django/forms/widgets/text.html" %}
|
||||||
list="{{ widget.name }}-list"
|
<datalist id="{{ widget.attrs.list }}">
|
||||||
type="{{ widget.type }}"
|
|
||||||
name="{{ widget.name }}"
|
|
||||||
{% if widget.value != None %}value="{{ widget.value|stringformat:'s' }}"{% endif %}
|
|
||||||
{% include "django/forms/widgets/attrs.html" %}>
|
|
||||||
<datalist id="{{ widget.name }}-list">
|
|
||||||
{% for option in widget.options %}<option value="{{ option }}"></option>{% endfor %}
|
{% for option in widget.options %}<option value="{{ option }}"></option>{% endfor %}
|
||||||
</datalist>
|
</datalist>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue