On simplifie le script
This commit is contained in:
parent
3b1c98d1fe
commit
9a785da53d
1 changed files with 8 additions and 27 deletions
|
@ -5,38 +5,18 @@
|
||||||
{% block extra_head %}
|
{% block extra_head %}
|
||||||
{% if question.vote_type == 'select' %}
|
{% if question.vote_type == 'select' %}
|
||||||
<script>
|
<script>
|
||||||
var selected = [];
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
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', () => {
|
document.getElementById('confirm-button').addEventListener('click', () => {
|
||||||
var $modal_body = document.getElementById('modal-body');
|
var $modal_body = document.getElementById('modal-body');
|
||||||
|
|
||||||
var selected_rows = '';
|
var selected_rows = '';
|
||||||
|
|
||||||
for (const s_id of selected) {
|
(document.querySelectorAll('.checkbox input') || []).forEach(($checkbox) => {
|
||||||
let option_text = document.getElementById(s_id).nextSibling.textContent.trim();
|
if ($checkbox.checked) {
|
||||||
selected_rows += '<tr><td>' + option_text + '</td></tr>\n';
|
let option_text = $checkbox.nextSibling.textContent.trim();
|
||||||
}
|
selected_rows += '<tr><td>' + option_text + '</td></tr>\n';
|
||||||
|
}
|
||||||
console.log(selected_rows);
|
});
|
||||||
|
|
||||||
$modal_body.innerHTML = `
|
$modal_body.innerHTML = `
|
||||||
<table class="table is-fullwidth">
|
<table class="table is-fullwidth">
|
||||||
|
@ -50,11 +30,12 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>`;
|
</table>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% elif question.vote_type == 'rank' %}
|
{% elif question.vote_type == 'rank' %}
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue