diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index 64b85d0b25..72df1371c3 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -14,6 +14,14 @@ class Meta: help_texts = {f: None for f in fields} +class ArrayWidget(forms.widgets.TextInput): + # pylint: disable=unused-argument + # pylint: disable=no-self-use + def value_from_datadict(self, data, files, name): + """get all values for this name""" + return [i for i in data.getlist(name) if i] + + class EditionForm(CustomForm): class Meta: model = models.Edition @@ -41,12 +49,10 @@ class Meta: "series_number": forms.TextInput( attrs={"aria-describedby": "desc_series_number"} ), + "subjects": ArrayWidget(), "languages": forms.TextInput( attrs={"aria-describedby": "desc_languages_help desc_languages"} ), - "subjects": forms.TextInput( - attrs={"aria-describedby": "desc_subjects_help desc_subjects"} - ), "publishers": forms.TextInput( attrs={"aria-describedby": "desc_publishers_help desc_publishers"} ), diff --git a/bookwyrm/static/js/forms.js b/bookwyrm/static/js/forms.js index 7d946d147b..9988738989 100644 --- a/bookwyrm/static/js/forms.js +++ b/bookwyrm/static/js/forms.js @@ -1,6 +1,19 @@ (function () { "use strict"; + /** + * Remoev input field + * + * @param {event} the button click event + */ + function removeInput(event) { + const trigger = event.currentTarget; + const input_id = trigger.dataset.remove; + const input = document.getElementById(input_id); + + input.remove(); + } + /** * Duplicate an input field * @@ -29,4 +42,8 @@ document .querySelectorAll("[data-duplicate]") .forEach((node) => node.addEventListener("click", duplicateInput)); + + document + .querySelectorAll("[data-remove]") + .forEach((node) => node.addEventListener("click", removeInput)); })(); diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index 38a7fe35d5..42f1840dfa 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -22,7 +22,7 @@

{% trans "Title:" %} - + {% include 'snippets/form_errors.html' with errors_list=form.title.errors id="desc_title" %} @@ -31,7 +31,7 @@

{% trans "Subtitle:" %} - + {% include 'snippets/form_errors.html' with errors_list=form.subtitle.errors id="desc_subtitle" %} @@ -40,7 +40,7 @@

{% trans "Description:" %} {{ form.description }} - + {% include 'snippets/form_errors.html' with errors_list=form.description.errors id="desc_description" %} @@ -51,7 +51,7 @@

{% trans "Series:" %} - + {% include 'snippets/form_errors.html' with errors_list=form.series.errors id="desc_series" %} @@ -61,7 +61,7 @@

{% trans "Series number:" %} {{ form.series_number }} - + {% include 'snippets/form_errors.html' with errors_list=form.series_number.errors id="desc_series_number" %} @@ -75,21 +75,60 @@

{% trans "Separate multiple values with commas." %} - + {% include 'snippets/form_errors.html' with errors_list=form.languages.errors id="desc_languages" %} -
-
@@ -106,7 +145,7 @@

{% trans "Separate multiple values with commas." %} - + {% include 'snippets/form_errors.html' with errors_list=form.publishers.errors id="desc_publishers" %} @@ -115,7 +154,7 @@

{% trans "First published date:" %} - + {% include 'snippets/form_errors.html' with errors_list=form.first_published_date.errors id="desc_first_published_date" %} @@ -124,7 +163,7 @@

{% trans "Published date:" %} - + {% include 'snippets/form_errors.html' with errors_list=form.published_date.errors id="desc_published_date" %} @@ -162,7 +201,12 @@

{% endfor %} - + + + @@ -193,7 +237,7 @@

- + {% include 'snippets/form_errors.html' with errors_list=form.cover.errors id="desc_cover" %} @@ -214,7 +258,7 @@

{{ form.physical_format }}
- + {% include 'snippets/form_errors.html' with errors_list=form.physical_format.errors id="desc_physical_format" %} @@ -224,7 +268,7 @@

{% trans "Format details:" %} {{ form.physical_format_detail }} - + {% include 'snippets/form_errors.html' with errors_list=form.physical_format_detail.errors id="desc_physical_format_detail" %} @@ -235,7 +279,7 @@

{% trans "Pages:" %} {{ form.pages }} - + {% include 'snippets/form_errors.html' with errors_list=form.pages.errors id="desc_pages" %} @@ -251,7 +295,7 @@

{% trans "ISBN 13:" %} {{ form.isbn_13 }} - + {% include 'snippets/form_errors.html' with errors_list=form.isbn_13.errors id="desc_isbn_13" %} @@ -260,7 +304,7 @@

{% trans "ISBN 10:" %} {{ form.isbn_10 }} - + {% include 'snippets/form_errors.html' with errors_list=form.isbn_10.errors id="desc_isbn_10" %} @@ -269,7 +313,7 @@

{% trans "Openlibrary ID:" %} {{ form.openlibrary_key }} - + {% include 'snippets/form_errors.html' with errors_list=form.openlibrary_key.errors id="desc_openlibrary_key" %} @@ -278,7 +322,7 @@

{% trans "Inventaire ID:" %} {{ form.inventaire_id }} - + {% include 'snippets/form_errors.html' with errors_list=form.inventaire_id.errors id="desc_inventaire_id" %} @@ -287,7 +331,7 @@

{% trans "OCLC Number:" %} {{ form.oclc_number }} - + {% include 'snippets/form_errors.html' with errors_list=form.oclc_number.errors id="desc_oclc_number" %} @@ -296,7 +340,7 @@

{% trans "ASIN:" %} {{ form.asin }} - + {% include 'snippets/form_errors.html' with errors_list=form.ASIN.errors id="desc_ASIN" %}