On simplifie le script

This commit is contained in:
Tom Hubrecht 2021-04-12 02:19:45 +02:00
parent 3b1c98d1fe
commit 9a785da53d

View file

@ -5,38 +5,18 @@
{% block extra_head %}
{% if question.vote_type == 'select' %}
<script>
var selected = [];
document.addEventListener('DOMContentLoaded', () => {
// À l'initialisation on remplit selected
(document.querySelectorAll('.checkbox input') || []).forEach(($checkbox) => {
if ($checkbox.checked) {
selected.push($checkbox.id);
}
});
(document.querySelectorAll('.checkbox input') || []).forEach(($checkbox) => {
$checkbox.addEventListener('change', () => {
var c_id = $checkbox.id;
if ($checkbox.checked) {
selected.push($checkbox.id);
} else {
selected = selected.filter(s_id => s_id != $checkbox.id);
}
});
});
document.getElementById('confirm-button').addEventListener('click', () => {
var $modal_body = document.getElementById('modal-body');
var selected_rows = '';
for (const s_id of selected) {
let option_text = document.getElementById(s_id).nextSibling.textContent.trim();
selected_rows += '<tr><td>' + option_text + '</td></tr>\n';
}
console.log(selected_rows);
(document.querySelectorAll('.checkbox input') || []).forEach(($checkbox) => {
if ($checkbox.checked) {
let option_text = $checkbox.nextSibling.textContent.trim();
selected_rows += '<tr><td>' + option_text + '</td></tr>\n';
}
});
$modal_body.innerHTML = `
<table class="table is-fullwidth">
@ -50,11 +30,12 @@
</tbody>
</table>`;
});
});
</script>
{% elif question.vote_type == 'rank' %}
<script>
</script>
{% endif %}
{% endblock %}