try make chosen answers global
This commit is contained in:
parent
8c976c1b61
commit
47406d1610
2 changed files with 46 additions and 8 deletions
|
@ -18,24 +18,59 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
{
|
(function() {
|
||||||
|
let last_answered = null;
|
||||||
|
|
||||||
// Create list of all subquestions
|
// Create list of all subquestions
|
||||||
const sub_questions = {};
|
const sub_questions = {};
|
||||||
<% for answer in question[:antwoorden]%>
|
const question_answers = {};
|
||||||
|
|
||||||
|
<% for answer in question[:antwoorden] %>
|
||||||
<% if answer[:vraag] %>
|
<% if answer[:vraag] %>
|
||||||
sub_questions['<%= answer[:tekst] + answer[:vraag] %>'] = document.getElementById('<%= answer[:tekst] + answer[:vraag] %>');
|
sub_questions['<%= answer[:tekst] + answer[:vraag] %>'] = document.getElementById('<%= answer[:tekst] + answer[:vraag] %>');
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
question_answers['<%= answer[:tekst] + (answer[:vraag] || "") %>'] = [];
|
||||||
|
|
||||||
|
<% if answer[:verenigingen] %>
|
||||||
|
<% for vereniging in answer[:verenigingen] %>
|
||||||
|
question_answers['<%= answer[:tekst] + (answer[:vraag] || "") %>'].push(
|
||||||
|
'<%= vereniging[:naam] %>'
|
||||||
|
);
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
document.getElementById("<%= question[:vraag] %>").addEventListener('change', (event) =>{
|
console.log('<%= (question[:vraag] || "") + (question[:tekst] || "") %>');
|
||||||
for (let t in sub_questions) {
|
console.log(question_answers);
|
||||||
sub_questions[t].style.display = "none";
|
|
||||||
|
document.getElementById("<%= question[:vraag] %>").addEventListener('change', (event) => {
|
||||||
|
if (last_answered && sub_questions[last_answered]) {
|
||||||
|
sub_questions[last_answered].style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let ver of question_answers[event.target.value] || []) {
|
||||||
|
console.log(ver);
|
||||||
|
if (answer_values[ver]) {
|
||||||
|
answer_values[ver] += 1;
|
||||||
|
} else {
|
||||||
|
answer_values[ver] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let ver of question_answers[last_answered] || []) {
|
||||||
|
answer_values[ver] -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(answer_values);
|
||||||
|
|
||||||
const quest = sub_questions[event.target.value];
|
const quest = sub_questions[event.target.value];
|
||||||
|
last_answered = event.target.value;
|
||||||
if (quest) {
|
if (quest) {
|
||||||
delete quest.style.removeProperty("display");
|
delete quest.style.removeProperty("display");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
<h1>Hallo</h1>
|
|
||||||
|
<script>
|
||||||
|
const answer_values = {};
|
||||||
|
</script>
|
||||||
|
|
||||||
<% @items.find_all("/quiz/*").each_with_index do |quest, i| %>
|
<% @items.find_all("/quiz/*").each_with_index do |quest, i| %>
|
||||||
<div id="question_<%=i%>" class="question">
|
<div id="question_<%=i%>" class="question">
|
||||||
<%= render '/partials/question.*', question: quest %>
|
<%= render '/partials/question.*', question: quest %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
|
|
Loading…
Reference in a new issue