Commit 29e3a03d by polesye

Merge pull request #1810 from edx/anton/fix-math-operations-in-numerical-input

Fix Numerical input to support mathematical operations.
parents c8adbe38 78149d0a
...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes, ...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected. the top. Include a label indicating the component affected.
Blades: Fix Numerical input to support mathematical operations. BLD-525.
Blades: Improve calculator's tooltip accessibility. Add possibility to navigate Blades: Improve calculator's tooltip accessibility. Add possibility to navigate
through the hints via arrow keys. BLD-533. through the hints via arrow keys. BLD-533.
......
...@@ -100,7 +100,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -100,7 +100,7 @@ describe 'MarkdownEditingDescriptor', ->
= 3.14159 +- .02 = 3.14159 +- .02
Enter the approximate value of 502*9: Enter the approximate value of 502*9:
= 4518 +- 15% = 502*9 +- 15%
Enter the number of fingers on a human hand: Enter the number of fingers on a human hand:
= 5 = 5
...@@ -125,7 +125,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -125,7 +125,7 @@ describe 'MarkdownEditingDescriptor', ->
</numericalresponse> </numericalresponse>
<p>Enter the approximate value of 502*9:</p> <p>Enter the approximate value of 502*9:</p>
<numericalresponse answer="4518"> <numericalresponse answer="502*9">
<responseparam type="tolerance" default="15%" /> <responseparam type="tolerance" default="15%" />
<formulaequationinput /> <formulaequationinput />
</numericalresponse> </numericalresponse>
......
...@@ -234,12 +234,15 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -234,12 +234,15 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
floatValue = parseFloat(answersList[0]); floatValue = parseFloat(answersList[0]);
if(!isNaN(floatValue)) { if(!isNaN(floatValue)) {
var params = /(.*?)\+\-\s*(.*?$)/.exec(answersList[0]); // Tries to extract parameters from string like 'expr +- tolerance'
var params = /(.*?)\+\-\s*(.*?$)/.exec(answersList[0]),
answer = answersList[0].replace(/\s+/g, '');
if(params) { if(params) {
string = '<numericalresponse answer="' + floatValue + '">\n'; answer = params[1].replace(/\s+/g, '');
string = '<numericalresponse answer="' + answer + '">\n';
string += ' <responseparam type="tolerance" default="' + params[2] + '" />\n'; string += ' <responseparam type="tolerance" default="' + params[2] + '" />\n';
} else { } else {
string = '<numericalresponse answer="' + floatValue + '">\n'; string = '<numericalresponse answer="' + answer + '">\n';
} }
string += ' <formulaequationinput />\n'; string += ' <formulaequationinput />\n';
string += '</numericalresponse>\n\n'; string += '</numericalresponse>\n\n';
......
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