Commit be723402 by Chandrakant Gopalan Committed by GitHub

Merge pull request #161 from open-craft/cgopalan/simplify-freeform-answer

OC-2959 freeform and MCQ submitted values are a json and not an array
parents 681cbda7 2a3145ce
...@@ -11,7 +11,7 @@ dependencies: ...@@ -11,7 +11,7 @@ dependencies:
- "pip install -r requirements.txt" - "pip install -r requirements.txt"
- "pip install -r $VIRTUAL_ENV/src/xblock-sdk/requirements/base.txt" - "pip install -r $VIRTUAL_ENV/src/xblock-sdk/requirements/base.txt"
- "pip install -r $VIRTUAL_ENV/src/xblock-sdk/requirements/test.txt" - "pip install -r $VIRTUAL_ENV/src/xblock-sdk/requirements/test.txt"
- "pip uninstall -y xblock-problem-builder && python setup.py sdist && pip install dist/xblock-problem-builder-2.7.1.tar.gz" - "pip uninstall -y xblock-problem-builder && python setup.py sdist && pip install dist/xblock-problem-builder-2.7.2.tar.gz"
- "pip install -r test_requirements.txt" - "pip install -r test_requirements.txt"
- "mkdir var" - "mkdir var"
test: test:
......
...@@ -249,8 +249,8 @@ The `answer_data` field contains these items: ...@@ -249,8 +249,8 @@ The `answer_data` field contains these items:
### POST Submit Data ### POST Submit Data
When submitting the problem either via Problem Builder or Step Builder, the data When submitting the problem either via Problem Builder or Step Builder, the data
entry corresponding to the Long Answer block should be an array with a single entry corresponding to the Long Answer block should be a single object
object containing the `"value"` property. Example: `[{"value": "Student's input"}]`. containing the `"value"` property. Example: `{"value": "Student's input"}`.
Multiple Choice Question (`pb-mcq`) Multiple Choice Question (`pb-mcq`)
----------------------------------- -----------------------------------
...@@ -298,8 +298,10 @@ Each entry in the `tips` array contains these values: ...@@ -298,8 +298,10 @@ Each entry in the `tips` array contains these values:
### POST Submit Data ### POST Submit Data
When submitting the problem the data should be equal to the string value of the When submitting the problem the data should be a single object containing the
selected choice. Example: `"blue"`. `"value"` property which has the value of the selected choice.
Example: `{"value": "blue"}`
Rating Question (`pb-rating`) Rating Question (`pb-rating`)
----------------------------- -----------------------------
......
...@@ -223,7 +223,7 @@ class AnswerBlock(SubmittingXBlockMixin, AnswerMixin, QuestionMixin, StudioEdita ...@@ -223,7 +223,7 @@ class AnswerBlock(SubmittingXBlockMixin, AnswerMixin, QuestionMixin, StudioEdita
The parent block is handling a student submission, including a new answer for this The parent block is handling a student submission, including a new answer for this
block. Update accordingly. block. Update accordingly.
""" """
self.student_input = submission[0]['value'].strip() self.student_input = submission['value'].strip()
self.save() self.save()
if sub_api: if sub_api:
......
...@@ -125,8 +125,8 @@ class MCQBlock(SubmittingXBlockMixin, StudentViewUserStateMixin, QuestionnaireAb ...@@ -125,8 +125,8 @@ class MCQBlock(SubmittingXBlockMixin, StudentViewUserStateMixin, QuestionnaireAb
def submit(self, submission): def submit(self, submission):
log.debug(u'Received MCQ submission: "%s"', submission) log.debug(u'Received MCQ submission: "%s"', submission)
result = self.calculate_results(submission) result = self.calculate_results(submission['value'])
self.student_choice = submission self.student_choice = submission['value']
log.debug(u'MCQ submission result: %s', result) log.debug(u'MCQ submission result: %s', result)
return result return result
......
...@@ -15,7 +15,13 @@ function AnswerBlock(runtime, element) { ...@@ -15,7 +15,13 @@ function AnswerBlock(runtime, element) {
}, },
submit: function() { submit: function() {
return $(':input', element).serializeArray(); var freeform_answer = $(':input', element);
if(freeform_answer.length) {
return {"value": freeform_answer.val()};
} else {
return null;
}
}, },
handleReview: function(result) { handleReview: function(result) {
......
...@@ -107,7 +107,7 @@ function MCQBlock(runtime, element) { ...@@ -107,7 +107,7 @@ function MCQBlock(runtime, element) {
var checkedRadio = $('input[type=radio]:checked', element); var checkedRadio = $('input[type=radio]:checked', element);
if(checkedRadio.length) { if(checkedRadio.length) {
return checkedRadio.val(); return {"value": checkedRadio.val()};
} else { } else {
return null; return null;
} }
......
...@@ -71,7 +71,7 @@ BLOCKS = [ ...@@ -71,7 +71,7 @@ BLOCKS = [
setup( setup(
name='xblock-problem-builder', name='xblock-problem-builder',
version='2.7.1', version='2.7.2',
description='XBlock - Problem Builder', description='XBlock - Problem Builder',
packages=['problem_builder', 'problem_builder.v1'], packages=['problem_builder', 'problem_builder.v1'],
install_requires=[ install_requires=[
......
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