From f21f8a8ac94b68727430ff4d67cc938bd7416218 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 2 Jun 2018 09:33:43 +0200 Subject: [PATCH] Improve editor selection in "no book" case. #4 --- manuels/static/manuels/no_book.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/manuels/static/manuels/no_book.js b/manuels/static/manuels/no_book.js index 2638ecb..ea762d7 100644 --- a/manuels/static/manuels/no_book.js +++ b/manuels/static/manuels/no_book.js @@ -4,10 +4,19 @@ document.addEventListener("DOMContentLoaded", function (event) { if (_selector.checked) { document.querySelector('#id_title').value = "PAS DE LIVRE POUR CETTE CLASSE"; document.querySelector('#id_authors').value = "N/A"; - document.querySelector('#id_editor').value = 1; document.querySelector('#id_publication_year').value = 1900; document.querySelector('#id_isbn').value = "0000000000"; document.querySelector('#id_price').value = 0; + var editorValue = null; + for (var option of document.querySelector('#id_editor').children) { + if (editorValue === null && option.value !== "") { + editorValue = option.value; + } + if (option.firstChild.data.toLowerCase().indexOf('autre') !== -1) { + editorValue = option.value; + } + } + document.querySelector('#id_editor').value = editorValue; } else { document.querySelector('#id_title').value = ""; document.querySelector('#id_authors').value = "";