diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index bf5efb46..e18087ee 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) + + )) } /** @@ -369,7 +376,9 @@ let BookWyrm = new class { } } - duplicateInput (input_id ) { + 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 diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index 841a3c53..25d24e43 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -128,7 +128,7 @@ {% endfor %} - {% trans "Add Another Author" %} + diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py index 0bacd607..917271fc 100644 --- a/bookwyrm/views/books/edit_book.py +++ b/bookwyrm/views/books/edit_book.py @@ -43,8 +43,8 @@ class EditBook(View): if not form.is_valid(): return TemplateResponse(request, "book/edit/edit_book.html", data) - add_author = request.POST.getlist("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"] = []