allow requirements on multiple choice questions
parent
46a8468f4d
commit
95f6b180a1
|
@ -7,6 +7,9 @@ function dep_check(expr) {
|
|||
var value = exprs[1];
|
||||
var qvalue = qvalues[qnum];
|
||||
if(value.substring(0,1) == "!") {
|
||||
var multiple_option = qvalues[qnum+'_'+value.substring(1)];
|
||||
if(multiple_option != undefined)
|
||||
return !multiple_option;
|
||||
value = value.substring(1);
|
||||
return qvalue != value;
|
||||
}
|
||||
|
@ -28,6 +31,10 @@ function dep_check(expr) {
|
|||
value = parseInt(value.substring(1));
|
||||
return qvalue > value;
|
||||
}
|
||||
var multiple_option = qvalues[qnum+'_'+value];
|
||||
if(multiple_option != undefined) {
|
||||
return multiple_option;
|
||||
}
|
||||
if(qvalues[qnum] == value) {
|
||||
return true;
|
||||
}
|
||||
|
@ -49,6 +56,8 @@ function statusChanged(obj, res) {
|
|||
|
||||
function valchanged(qnum, value) {
|
||||
qvalues[qnum] = value;
|
||||
// qnum may be 'X_Y' for option Y of multiple choice question X
|
||||
qnum = qnum.split('_')[0];
|
||||
for (var t in qtriggers) {
|
||||
t = qtriggers[t];
|
||||
checks = getChecksAttr(t);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load i18n %}
|
||||
{% for choice, key, checked in qdict.choices %}
|
||||
<input type="checkbox" id="{{ key }}" name="{{ key }}" value="{{ choice.value }}" {{ checked }}><label for="{{ key }}"> {{ choice.text }}</label>{% if not qdict.nobreaks %}<br />{% endif %}
|
||||
<input onClick="valchanged('{{ question.number }}_{{ choice.value }}', this.checked);" type="checkbox" id="{{ key }}" name="{{ key }}" value="{{ choice.value }}" {{ checked }}><label for="{{ key }}"> {{ choice.text }}</label>{% if not qdict.nobreaks %}<br />{% endif %}
|
||||
{% endfor %}
|
||||
{% if qdict.extras %}
|
||||
{% if question.extra %}<label for="question_{{ question.number }}_more1">{{ question.extra }}</label><br />{% endif %}
|
||||
|
|
|
@ -83,7 +83,7 @@ img.percentImage {
|
|||
<script type="text/javascript">
|
||||
{% for trigger in triggers %}addtrigger("{{trigger}}");
|
||||
{% endfor %}
|
||||
{% for k,v in qvalues.items %}qvalues['{{ k }}'] = '{{ v|escapejs }}';
|
||||
{% for k,v in qvalues.items %}qvalues['{{ k|escapejs }}'] = '{{ v|escapejs }}';
|
||||
{% endfor %}
|
||||
for(key in qvalues) {
|
||||
valchanged(key, qvalues[key]);
|
||||
|
|
|
@ -369,7 +369,9 @@ def show_questionnaire(request, runinfo, errors={}):
|
|||
for k,v in request.POST.items():
|
||||
if k.startswith("question_"):
|
||||
s = k.split("_")
|
||||
if len(s) == 2:
|
||||
if len(s) == 4:
|
||||
qvalues[s[1]+'_'+v] = '1' # evaluates true in JS
|
||||
else:
|
||||
qvalues[s[1]] = v
|
||||
|
||||
r = r2r("questionnaire/questionset.html", request,
|
||||
|
@ -492,6 +494,16 @@ def dep_check(expr, runinfo, answerdict):
|
|||
except Question.DoesNotExist:
|
||||
return False
|
||||
if check_question in answerdict:
|
||||
# test for membership in multiple choice questions
|
||||
# FIXME: only checking answerdict
|
||||
for k, v in answerdict[check_question].items():
|
||||
if not k.startswith('multiple_'):
|
||||
continue
|
||||
if check_answer.startswith("!"):
|
||||
if check_answer[1:].strip() == v.strip():
|
||||
return False
|
||||
elif check_answer.strip() == v.strip():
|
||||
return True
|
||||
actual_answer = answerdict[check_question].get('ANSWER', '')
|
||||
elif runinfo.get_cookie(check_questionnum, False):
|
||||
actual_answer = runinfo.get_cookie(check_questionnum)
|
||||
|
|
Loading…
Reference in New Issue