forked from mirrors/bookwyrm
Standardize JS, use button, & filter empty authors
This commit is contained in:
parent
6be9ac4f70
commit
66e414be3c
3 changed files with 13 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -128,7 +128,7 @@
|
|||
<input class="input" type="text" name="add_author" id="id_add_author" placeholder="{% trans 'Jane Doe' %}" value="{{ author }}" {% if confirm_mode %}readonly{% endif %}>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<span class="help"><a id="another_author_field" onclick="BookWyrm.duplicateInput('id_add_author')">{% trans "Add Another Author" %}</a></span>
|
||||
<span class="help"><button class="button is-small" type="button" data-duplicate="id_add_author" id="another_author_field">{% trans "Add Another Author" %}</button></span>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
|
|
@ -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"] = []
|
||||
|
|
Loading…
Reference in a new issue