fix old answers are shown in results

This commit is contained in:
ajuvercr 2020-09-14 22:27:46 +02:00
parent 09ec6f507c
commit edfd9c02ac
2 changed files with 11 additions and 1 deletions

View file

@ -74,7 +74,7 @@
const sub_questions = {};
// Create list of all student organisations this answer entails
const question_results = {};
<% question[:antwoorden].each_with_index do |answer, idx| %>
<% question[:antwoorden].sort_by{ |x| x[:tekst] }.each_with_index do |answer, idx| %>
<% if answer[:vraag] %>sub_questions['<%= number+"#"+idx.to_s %>'] = document.getElementById('<%= number+"#"+idx.to_s %>');<% end %>
question_results['<%= number+"#"+idx.to_s %>'] = <%= (answer[:verenigingen] || []).map { |vereniging| vereniging[:naam] }.to_a %>;
<% end %>

View file

@ -42,6 +42,13 @@
return this;
}
Array.prototype.sortByKey = function(key) {
return this.sort(function(a, b) {
var x = key(a); var y = key(b);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
const _results = <%= to_partials(all_groups()) %>;
// This keeps the state of the current question/result
@ -146,6 +153,7 @@
}
function show_result(result) {
console.log(result);
while (resultWrapper.lastElementChild) {
resultWrapper.removeChild(resultWrapper.lastElementChild);
}
@ -156,6 +164,8 @@
continue;
}
if(!val) continue;
const create_wrapper= document.createElement('div');
create_wrapper.innerHTML = _results[ver];
create_wrapper.style.order = val;