From 5577d3632e1b20466dab1c4bbcc2d7e7bfb15294 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 13 Jul 2020 14:42:12 +0100 Subject: [PATCH] Vertical forms --- .../rest_framework/vertical/checkbox.html | 16 +++--- .../vertical/checkbox_multiple.html | 41 +++++++--------- .../rest_framework/vertical/dict_field.html | 4 +- .../rest_framework/vertical/fieldset.html | 4 +- .../rest_framework/vertical/input.html | 10 ++-- .../rest_framework/vertical/list_field.html | 4 +- .../vertical/list_fieldset.html | 6 +-- .../rest_framework/vertical/radio.html | 49 ++++++------------- .../rest_framework/vertical/select.html | 10 ++-- .../vertical/select_multiple.html | 12 ++--- .../rest_framework/vertical/textarea.html | 10 ++-- tests/test_bound_fields.py | 14 +++--- 12 files changed, 74 insertions(+), 106 deletions(-) diff --git a/rest_framework/templates/rest_framework/vertical/checkbox.html b/rest_framework/templates/rest_framework/vertical/checkbox.html index cdc8eee32..b99499f4b 100644 --- a/rest_framework/templates/rest_framework/vertical/checkbox.html +++ b/rest_framework/templates/rest_framework/vertical/checkbox.html @@ -1,18 +1,16 @@ -
-
- -
+
+
+ + {% if field.label %}{% endif %} {% if field.errors %} {% for error in field.errors %} - {{ error }} + {{ error }} {% endfor %} {% endif %} {% if field.help_text %} - {{ field.help_text|safe }} + {{ field.help_text|safe }} {% endif %} +
diff --git a/rest_framework/templates/rest_framework/vertical/checkbox_multiple.html b/rest_framework/templates/rest_framework/vertical/checkbox_multiple.html index 5aed1519a..c5cc45a5a 100644 --- a/rest_framework/templates/rest_framework/vertical/checkbox_multiple.html +++ b/rest_framework/templates/rest_framework/vertical/checkbox_multiple.html @@ -1,37 +1,30 @@ {% load rest_framework %} -
+
{% if field.label %} - + {% endif %} - {% if style.inline %} -
- {% for key, text in field.choices|items %} - - {% endfor %} -
- {% else %} +
{% for key, text in field.choices|items %} -
- +
+ +
{% endfor %} - {% endif %} - {% if field.errors %} - {% for error in field.errors %} - {{ error }} - {% endfor %} - {% endif %} + {% if field.errors %} + {# A fake input to trigger the error messages as it needs to be after a valid input #} + {# If it's with the last input and it's inline then the error stacks under the last input label #} + {# It has no name so no data will be sent #} + + {% for error in field.errors %} + {{ error }} + {% endfor %} + {% endif %} {% if field.help_text %} - {{ field.help_text|safe }} + {{ field.help_text|safe }} {% endif %}
+
\ No newline at end of file diff --git a/rest_framework/templates/rest_framework/vertical/dict_field.html b/rest_framework/templates/rest_framework/vertical/dict_field.html index a46759196..335b60c50 100644 --- a/rest_framework/templates/rest_framework/vertical/dict_field.html +++ b/rest_framework/templates/rest_framework/vertical/dict_field.html @@ -1,7 +1,7 @@
{% if field.label %} - + {% endif %} -

Dictionaries are not currently supported in HTML input.

+

Dictionaries are not currently supported in HTML input.

diff --git a/rest_framework/templates/rest_framework/vertical/fieldset.html b/rest_framework/templates/rest_framework/vertical/fieldset.html index 4ec2a5d48..3fdac3539 100644 --- a/rest_framework/templates/rest_framework/vertical/fieldset.html +++ b/rest_framework/templates/rest_framework/vertical/fieldset.html @@ -2,9 +2,7 @@
{% if field.label %} - - {{ field.label }} - + {% endif %} {% for nested_field in field %} diff --git a/rest_framework/templates/rest_framework/vertical/input.html b/rest_framework/templates/rest_framework/vertical/input.html index 6bcd3d93d..26711ccda 100644 --- a/rest_framework/templates/rest_framework/vertical/input.html +++ b/rest_framework/templates/rest_framework/vertical/input.html @@ -1,17 +1,17 @@ -
+
{% if field.label %} - + {% endif %} - + {% if field.errors %} {% for error in field.errors %} - {{ error }} + {{ error }} {% endfor %} {% endif %} {% if field.help_text %} - {{ field.help_text|safe }} + {{ field.help_text|safe }} {% endif %}
diff --git a/rest_framework/templates/rest_framework/vertical/list_field.html b/rest_framework/templates/rest_framework/vertical/list_field.html index f5a724ad2..67dfb44f9 100644 --- a/rest_framework/templates/rest_framework/vertical/list_field.html +++ b/rest_framework/templates/rest_framework/vertical/list_field.html @@ -1,7 +1,7 @@
{% if field.label %} - + {% endif %} -

Lists are not currently supported in HTML input.

+

Lists are not currently supported in HTML input.

diff --git a/rest_framework/templates/rest_framework/vertical/list_fieldset.html b/rest_framework/templates/rest_framework/vertical/list_fieldset.html index f2b615fe1..a2e05d8e0 100644 --- a/rest_framework/templates/rest_framework/vertical/list_fieldset.html +++ b/rest_framework/templates/rest_framework/vertical/list_fieldset.html @@ -1,9 +1,7 @@
{% if field.label %} - - {{ field.label }} - + {% endif %} -

Lists are not currently supported in HTML input.

+

Lists are not currently supported in HTML input.

diff --git a/rest_framework/templates/rest_framework/vertical/radio.html b/rest_framework/templates/rest_framework/vertical/radio.html index 3d8ec0690..98c17ad1f 100644 --- a/rest_framework/templates/rest_framework/vertical/radio.html +++ b/rest_framework/templates/rest_framework/vertical/radio.html @@ -2,56 +2,39 @@ {% load rest_framework %} {% trans "None" as none_choice %} -
+
{% if field.label %} -
' '' - '' + 'Textfield' '' '
' ''