From a30a53a09d2a8b74b8e408e2baaaebe4613e05f2 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 26 Dec 2018 18:30:15 +0300 Subject: [PATCH] Bugfix: Text Input problem type expects numeric answer when correct answer starts with a number --- .../xmodule/xmodule/js/spec/problem/edit_spec.js | 7 +++++++ common/lib/xmodule/xmodule/js/src/problem/edit.js | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.js b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.js index c09419a5fe..7ac7869bae 100644 --- a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.js @@ -156,6 +156,9 @@ If first and last symbols are not brackets, or they are not closed, stringrespon = (7), 7 = (1+2 +Just input 100 test. Stringresponse will appear: += 100 test + [Explanation] Pi, or the the ratio between a circle's circumference to its diameter, is an irrational number known to extreme precision. It is value is approximately equal to 3.14. @@ -195,6 +198,10 @@ If you look at your hand, you can count that you have five fingers. +

Just input 100 test. Stringresponse will appear:

+ + +

Explanation

diff --git a/common/lib/xmodule/xmodule/js/src/problem/edit.js b/common/lib/xmodule/xmodule/js/src/problem/edit.js index 7aa6159d49..f393742745 100644 --- a/common/lib/xmodule/xmodule/js/src/problem/edit.js +++ b/common/lib/xmodule/xmodule/js/src/problem/edit.js @@ -573,6 +573,17 @@ ); }, + checkIsNumeric = function(stringValue) { + // remove OLX feedback + if ((stringValue.indexOf('{{') !== -1) && (stringValue.indexOf('}}') !== -1)) { + stringValue = stringValue.replace(/{{[\s\S]*?}}/g, '').trim(); + } + if (stringValue.match(/[a-z]/i)) { + return false; + } + return !isNaN(parseFloat(stringValue)); + }, + getAnswerData = function(answerValue) { var answerData = {}, answerParams = /(.*?)\+\-\s*(.*?$)/.exec(answerValue); @@ -593,7 +604,7 @@ firstAnswer = answerValues[0].replace(/^\=\s*/, ''); // If answer is not numerical - if (isNaN(parseFloat(firstAnswer)) && !isRangeToleranceCase(firstAnswer)) { + if (!checkIsNumeric(firstAnswer) && !isRangeToleranceCase(firstAnswer)) { return false; }