Commit 958060a0 by Joe Blaylock

TIM-435: Prevent whitespace-only submissions

parent 86c20003
...@@ -65,6 +65,13 @@ describe("OpenAssessment.ResponseView", function() { ...@@ -65,6 +65,13 @@ describe("OpenAssessment.ResponseView", function() {
expect(view.saveEnabled()).toBe(false); expect(view.saveEnabled()).toBe(false);
expect(view.saveStatus()).toContain('Unsaved draft'); expect(view.saveStatus()).toContain('Unsaved draft');
// Response is whitespace --> save/submit buttons disabled
view.response(' \n \n ');
view.responseChanged();
expect(view.submitEnabled()).toBe(false);
expect(view.saveEnabled()).toBe(false);
expect(view.saveStatus()).toContain('Unsaved draft');
// Response is not blank --> submit button enabled // Response is not blank --> submit button enabled
view.response('Test response'); view.response('Test response');
view.responseChanged(); view.responseChanged();
......
...@@ -170,12 +170,12 @@ OpenAssessment.ResponseView.prototype = { ...@@ -170,12 +170,12 @@ OpenAssessment.ResponseView.prototype = {
**/ **/
responseChanged: function() { responseChanged: function() {
// Enable the save/submit button only for non-blank responses // Enable the save/submit button only for non-blank responses
var currentResponse = this.response(); var currentResponse = $.trim(this.response());
var isBlank = (currentResponse !== ''); var isBlank = (currentResponse !== '');
this.submitEnabled(isBlank); this.submitEnabled(isBlank);
// Update the save button and status only if the response has changed // Update the save button and status only if the response has changed
if (this.savedResponse !== currentResponse) { if ($.trim(this.savedResponse) !== currentResponse) {
this.saveEnabled(isBlank); this.saveEnabled(isBlank);
this.saveStatus('Unsaved draft'); this.saveStatus('Unsaved draft');
} }
......
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