From e2ce977756edb4f205d0241386c3251e81ec57eb Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Tue, 23 Sep 2014 18:04:46 +0500 Subject: [PATCH] Fixed multiple JsInput's in problem. TNL-269 --- .../xmodule/js/fixtures/jsinput_problem.html | 53 +++++++++++++++++++ .../xmodule/js/spec/capa/display_spec.coffee | 11 ++++ .../xmodule/js/src/capa/display.coffee | 6 ++- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 common/lib/xmodule/xmodule/js/fixtures/jsinput_problem.html diff --git a/common/lib/xmodule/xmodule/js/fixtures/jsinput_problem.html b/common/lib/xmodule/xmodule/js/fixtures/jsinput_problem.html new file mode 100644 index 0000000000..0e133de9ff --- /dev/null +++ b/common/lib/xmodule/xmodule/js/fixtures/jsinput_problem.html @@ -0,0 +1,53 @@ +

Custom Javascript Display and Grading

+ +
+
+ +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+
+ +
+ + + +
+
diff --git a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee index 203a70d9d1..cbc05b0302 100644 --- a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee @@ -604,3 +604,14 @@ describe 'Problem', -> xit 'serialize all answers', -> @problem.refreshAnswers() expect(@problem.answers).toEqual "input_1_1=one&input_1_2=two" + + describe 'multiple JsInput in single problem', -> + jsinput_html = readFixtures('jsinput_problem.html') + + beforeEach -> + @problem = new Problem($('.xblock-student_view')) + @problem.render(jsinput_html) + + it 'check_save_waitfor should return false', -> + $(@problem.inputs[0]).data('waitfor', ->) + expect(@problem.check_save_waitfor()).toEqual(false) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 592c9b3a0c..5fa03e381e 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -180,6 +180,7 @@ class @Problem # and specify the function to be called by the check button before sending # off @answers check_save_waitfor: (callback) => + flag = false for inp in @inputs if ($(inp).is("input[waitfor]")) try @@ -193,9 +194,10 @@ class @Problem else alert "Could not grade your answer. The submission was aborted." throw e - return true + flag = true else - return false + flag = false + return flag ###