diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 2d5b88adc..e18087eeb 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -45,6 +45,13 @@ let BookWyrm = new class { 'change', this.disableIfTooLarge.bind(this) )); + + document.querySelectorAll('[data-duplicate]') + .forEach(node => node.addEventListener( + 'click', + this.duplicateInput.bind(this) + + )) } /** @@ -368,4 +375,24 @@ let BookWyrm = new class { ); } } + + duplicateInput (event ) { + const trigger = event.currentTarget; + const input_id = trigger.dataset['duplicate'] + const orig = document.getElementById(input_id); + const parent = orig.parentNode; + const new_count = parent.querySelectorAll("input").length + 1 + + let input = orig.cloneNode(); + + input.id += ("-" + (new_count)) + input.value = "" + + let label = parent.querySelector("label").cloneNode(); + + label.setAttribute("for", input.id) + + parent.appendChild(label) + parent.appendChild(input) + } }(); diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index 982bb56d2..25d24e43d 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -119,10 +119,16 @@ {% endif %}
- - - {% trans "Separate multiple values with commas." %} + + {% for author in add_author %} + + + {% empty %} + + + {% endfor %}
+ diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py index fc13aa6c4..755c25b4c 100644 --- a/bookwyrm/views/books/edit_book.py +++ b/bookwyrm/views/books/edit_book.py @@ -51,13 +51,14 @@ class EditBook(View): if not form.is_valid(): return TemplateResponse(request, "book/edit/edit_book.html", data) - add_author = request.POST.get("add_author") - # we're adding an author through a free text field + # filter out empty author fields + add_author = [author for author in request.POST.getlist("add_author") if author] if add_author: data["add_author"] = add_author data["author_matches"] = [] data["isni_matches"] = [] - for author in add_author.split(","): + + for author in add_author: if not author: continue # check for existing authors