Commit 943a3a5e by muhammad-ammar

single form element per capa problem

TNL-5402
parent dda92d13
<%! from openedx.core.djangolib.markup import HTML %> <%! from openedx.core.djangolib.markup import HTML %>
<form class="annotation-input"> <div class="annotation-input">
<div class="script_placeholder" data-src="${STATIC_URL}js/capa/annotationinput.js"/> <div class="script_placeholder" data-src="${STATIC_URL}js/capa/annotationinput.js"/>
<div class="annotation-header"> <div class="annotation-header">
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<p id="answer_${id}" class="answer answer-annotation"></p> <p id="answer_${id}" class="answer answer-annotation"></p>
</div> </div>
</form> </div>
% if msg: % if msg:
<span class="message">${HTML(msg)}</span> <span class="message">${HTML(msg)}</span>
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
not isinstance(value, basestring) and choice_id in value not isinstance(value, basestring) and choice_id in value
)) ))
%> %>
<form class="choicegroup capa_inputtype" id="inputtype_${id}">
<div class="choicegroup capa_inputtype" id="inputtype_${id}">
<fieldset ${HTML(describedby_html)}> <fieldset ${HTML(describedby_html)}>
% if response_data['label']: % if response_data['label']:
<legend id="${id}-legend" class="response-fieldset-legend field-group-hd">${response_data['label']}</legend> <legend id="${id}-legend" class="response-fieldset-legend field-group-hd">${response_data['label']}</legend>
...@@ -71,4 +72,4 @@ ...@@ -71,4 +72,4 @@
% if msg: % if msg:
<span class="message">${HTML(msg)}</span> <span class="message">${HTML(msg)}</span>
% endif % endif
</form> </div>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
%endif %endif
% endfor % endfor
<section id="choicetextinput_${id}" class="choicetextinput"> <section id="choicetextinput_${id}" class="choicetextinput">
<form class="choicetextgroup capa_inputtype" id="inputtype_${id}"> <div class="choicetextgroup capa_inputtype" id="inputtype_${id}">
<div class="script_placeholder" data-src="${STATIC_URL}js/capa/choicetextinput.js"/> <div class="script_placeholder" data-src="${STATIC_URL}js/capa/choicetextinput.js"/>
<fieldset aria-label="${remove_markup(response_data['label'])}"> <fieldset aria-label="${remove_markup(response_data['label'])}">
...@@ -73,5 +73,5 @@ ...@@ -73,5 +73,5 @@
% if msg: % if msg:
<span class="message">${msg|n}</span> <span class="message">${msg|n}</span>
% endif % endif
</form> </div>
</section> </section>
<form class="javascriptinput capa_inputtype" id="inputtype_${id}"> <div class="javascriptinput capa_inputtype" id="inputtype_${id}">
<input type="hidden" name="input_${id}" id="input_${id}" class="javascriptinput_input"/> <input type="hidden" name="input_${id}" id="input_${id}" class="javascriptinput_input"/>
<div class="javascriptinput_data" data-display_class="${display_class}" <div class="javascriptinput_data" data-display_class="${display_class}"
data-problem_state="${problem_state}" data-params="${params}" data-problem_state="${problem_state}" data-params="${params}"
data-submission="${value|h}" data-evaluation="${msg|h}"> data-submission="${value|h}" data-evaluation="${msg|h}">
</div> </div>
<div class="script_placeholder" data-src="/static/js/${display_file}"></div> <div class="script_placeholder" data-src="/static/js/${display_file}"></div>
<div class="javascriptinput_container"></div> <div class="javascriptinput_container"></div>
</form> </div>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<%! from openedx.core.djangolib.markup import HTML %> <%! from openedx.core.djangolib.markup import HTML %>
<% doinline = "inline" if inline else "" %> <% doinline = "inline" if inline else "" %>
<form class="inputtype option-input ${doinline}"> <div class="inputtype option-input ${doinline}">
% if response_data['label']: % if response_data['label']:
<label class="problem-group-label" for="input_${id}">${response_data['label']}</label> <label class="problem-group-label" for="input_${id}">${response_data['label']}</label>
% endif % endif
...@@ -31,4 +31,4 @@ ...@@ -31,4 +31,4 @@
% if msg: % if msg:
<span class="message">${HTML(msg)}</span> <span class="message">${HTML(msg)}</span>
% endif % endif
</form> </div>
...@@ -1288,17 +1288,16 @@ class CapaMixin(CapaFields): ...@@ -1288,17 +1288,16 @@ class CapaMixin(CapaFields):
if is_correct is None: if is_correct is None:
is_correct = '' is_correct = ''
response_data = getattr(answer_input, 'response_data', {})
input_metadata[input_id] = { input_metadata[input_id] = {
'question': answer_input.response_data.get('label', ''), 'question': response_data.get('label', ''),
'answer': user_visible_answer, 'answer': user_visible_answer,
'response_type': getattr(getattr(answer_response, 'xml', None), 'tag', ''), 'response_type': getattr(getattr(answer_response, 'xml', None), 'tag', ''),
'input_type': getattr(answer_input, 'tag', ''), 'input_type': getattr(answer_input, 'tag', ''),
'correct': is_correct, 'correct': is_correct,
'variant': variant, 'variant': variant,
'group_label': response_data.get('group_label', ''),
} }
# Add group_label in event data only if the responsetype contains multiple inputtypes
if answer_input.response_data.get('group_label'):
input_metadata[input_id]['group_label'] = answer_input.response_data.get('group_label')
return input_metadata return input_metadata
......
...@@ -2600,6 +2600,7 @@ class TestProblemCheckTracking(unittest.TestCase): ...@@ -2600,6 +2600,7 @@ class TestProblemCheckTracking(unittest.TestCase):
'response_type': 'optionresponse', 'response_type': 'optionresponse',
'input_type': 'optioninput', 'input_type': 'optioninput',
'correct': True, 'correct': True,
'group_label': '',
'variant': '', 'variant': '',
}, },
factory.answer_key(3): { factory.answer_key(3): {
...@@ -2608,6 +2609,7 @@ class TestProblemCheckTracking(unittest.TestCase): ...@@ -2608,6 +2609,7 @@ class TestProblemCheckTracking(unittest.TestCase):
'response_type': 'multiplechoiceresponse', 'response_type': 'multiplechoiceresponse',
'input_type': 'choicegroup', 'input_type': 'choicegroup',
'correct': False, 'correct': False,
'group_label': '',
'variant': '', 'variant': '',
}, },
factory.answer_key(4): { factory.answer_key(4): {
...@@ -2616,6 +2618,7 @@ class TestProblemCheckTracking(unittest.TestCase): ...@@ -2616,6 +2618,7 @@ class TestProblemCheckTracking(unittest.TestCase):
'response_type': 'choiceresponse', 'response_type': 'choiceresponse',
'input_type': 'checkboxgroup', 'input_type': 'checkboxgroup',
'correct': False, 'correct': False,
'group_label': '',
'variant': '', 'variant': '',
}, },
}) })
...@@ -2656,6 +2659,7 @@ class TestProblemCheckTracking(unittest.TestCase): ...@@ -2656,6 +2659,7 @@ class TestProblemCheckTracking(unittest.TestCase):
'response_type': 'numericalresponse', 'response_type': 'numericalresponse',
'input_type': 'textline', 'input_type': 'textline',
'correct': True, 'correct': True,
'group_label': '',
'variant': '', 'variant': '',
} }
}) })
...@@ -2787,6 +2791,7 @@ class TestProblemCheckTracking(unittest.TestCase): ...@@ -2787,6 +2791,7 @@ class TestProblemCheckTracking(unittest.TestCase):
'response_type': 'numericalresponse', 'response_type': 'numericalresponse',
'input_type': 'textline', 'input_type': 'textline',
'correct': True, 'correct': True,
'group_label': '',
'variant': module.seed, 'variant': module.seed,
} }
}) })
...@@ -2819,11 +2824,13 @@ class TestProblemCheckTracking(unittest.TestCase): ...@@ -2819,11 +2824,13 @@ class TestProblemCheckTracking(unittest.TestCase):
'response_type': 'coderesponse', 'response_type': 'coderesponse',
'input_type': 'filesubmission', 'input_type': 'filesubmission',
'correct': False, 'correct': False,
'group_label': '',
'variant': '', 'variant': '',
}, },
factory.answer_key(3): { factory.answer_key(3): {
'answer': 'None', 'answer': 'None',
'correct': True, 'correct': True,
'group_label': '',
'question': '', 'question': '',
'response_type': 'customresponse', 'response_type': 'customresponse',
'input_type': 'textline', 'input_type': 'textline',
......
...@@ -216,7 +216,7 @@ def answer_problem(course, problem_type, correctness): ...@@ -216,7 +216,7 @@ def answer_problem(course, problem_type, correctness):
world.css_fill(inputfield(course, 'string'), textvalue) world.css_fill(inputfield(course, 'string'), textvalue)
elif problem_type == 'numerical': elif problem_type == 'numerical':
textvalue = "pi + 1" if correctness == 'correct' else str(random.randint(-2, 2)) textvalue = "pi+1" if correctness == 'correct' else str(random.randint(-2, 2))
world.css_fill(inputfield(course, 'numerical'), textvalue) world.css_fill(inputfield(course, 'numerical'), textvalue)
elif problem_type == 'formula': elif problem_type == 'formula':
......
...@@ -12,6 +12,8 @@ from openedx.core.djangolib.markup import HTML ...@@ -12,6 +12,8 @@ from openedx.core.djangolib.markup import HTML
<div class="problem-progress"></div> <div class="problem-progress"></div>
<div class="problem"> <div class="problem">
## onsubmit is required because click on any button inside form will submit it and reload page which we don't want
<form class='capa-problem-form' onsubmit='return false;'>
${ HTML(problem['html']) } ${ HTML(problem['html']) }
<div class="action"> <div class="action">
<input type="hidden" name="problem_id" value="${ problem['name'] }" /> <input type="hidden" name="problem_id" value="${ problem['name'] }" />
...@@ -39,4 +41,5 @@ from openedx.core.djangolib.markup import HTML ...@@ -39,4 +41,5 @@ from openedx.core.djangolib.markup import HTML
</div> </div>
% endif % endif
</div> </div>
</form>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment