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',
|
'change',
|
||||||
this.disableIfTooLarge.bind(this)
|
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 orig = document.getElementById(input_id);
|
||||||
const parent = orig.parentNode;
|
const parent = orig.parentNode;
|
||||||
const new_count = parent.querySelectorAll("input").length + 1
|
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 %}>
|
<input class="input" type="text" name="add_author" id="id_add_author" placeholder="{% trans 'Jane Doe' %}" value="{{ author }}" {% if confirm_mode %}readonly{% endif %}>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -43,8 +43,8 @@ class EditBook(View):
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return TemplateResponse(request, "book/edit/edit_book.html", data)
|
return TemplateResponse(request, "book/edit/edit_book.html", data)
|
||||||
|
|
||||||
add_author = request.POST.getlist("add_author")
|
# filter out empty author fields
|
||||||
# we're adding an author through a free text field
|
add_author = [author for author in request.POST.getlist("add_author") if author]
|
||||||
if add_author:
|
if add_author:
|
||||||
data["add_author"] = add_author
|
data["add_author"] = add_author
|
||||||
data["author_matches"] = []
|
data["author_matches"] = []
|
||||||
|
|
Loading…
Reference in a new issue