From 18478113e513e2124cb8089aecc6e2a3c2170cc4 Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Mon, 21 Oct 2024 12:41:56 -0600 Subject: [PATCH 1/6] Add has-error class --- js/views/questionView.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/views/questionView.js b/js/views/questionView.js index f08ce9dd..a80f504c 100644 --- a/js/views/questionView.js +++ b/js/views/questionView.js @@ -49,7 +49,7 @@ class QuestionView extends ComponentView { preRender() { // Setup listener for _isEnabled this.listenTo(this.model, 'change:_isEnabled', this.onEnabledChanged); - + this.listenTo(this.model, 'change:_isSubmitted', this.onSubmittedChanged); this.listenTo(this.model, 'question:refresh', this.refresh); // Checks to see if the question should be reset on revisit @@ -79,6 +79,11 @@ class QuestionView extends ComponentView { } + onSubmittedChanged(model) { + // Remove error class, if it exists + model.toggleClass('has-error', false); + } + // Used by the question to disable the question during submit and complete stages disableQuestion() {} @@ -175,6 +180,7 @@ class QuestionView extends ComponentView { if (!canSubmit) { this.showInstructionError(); + this.addErrorClass(); this.onCannotSubmit(); return; } @@ -240,6 +246,10 @@ class QuestionView extends ComponentView { Adapt.trigger('questionView:showInstructionError', this); } + addErrorClass() { + this.model.toggleClass('has-error', true); + } + // Blank method for question to fill out when the question cannot be submitted onCannotSubmit() {} From 12bf8a95e39cb1fe4842428187385abfa7218f81 Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Tue, 22 Oct 2024 08:54:42 -0600 Subject: [PATCH 2/6] Combine listener lines --- js/views/questionView.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/views/questionView.js b/js/views/questionView.js index a80f504c..4344da4b 100644 --- a/js/views/questionView.js +++ b/js/views/questionView.js @@ -47,10 +47,11 @@ class QuestionView extends ComponentView { } preRender() { - // Setup listener for _isEnabled - this.listenTo(this.model, 'change:_isEnabled', this.onEnabledChanged); - this.listenTo(this.model, 'change:_isSubmitted', this.onSubmittedChanged); - this.listenTo(this.model, 'question:refresh', this.refresh); + this.listenTo(this.model, { + 'change:_isEnabled': this.onEnabledChanged, + 'change:_isSubmitted': this.onSubmittedChanged, + 'question:refresh': this.refresh + }); // Checks to see if the question should be reset on revisit if (this.checkIfResetOnRevisit !== QuestionView.prototype.checkIfResetOnRevisit) { From 87c1eab56c90b3f8a96c8d442399ad155f6bd8d0 Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Tue, 22 Oct 2024 08:57:16 -0600 Subject: [PATCH 3/6] Move error toggle class --- js/views/questionView.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/views/questionView.js b/js/views/questionView.js index 4344da4b..52ee4148 100644 --- a/js/views/questionView.js +++ b/js/views/questionView.js @@ -245,9 +245,6 @@ class QuestionView extends ComponentView { showInstructionError() { Adapt.trigger('questionView:showInstructionError', this); - } - - addErrorClass() { this.model.toggleClass('has-error', true); } From 85318161006942bff2e06935ebc7745b05c5c9f9 Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Tue, 22 Oct 2024 09:03:36 -0600 Subject: [PATCH 4/6] Reorder showInstructionError lines --- js/views/questionView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/views/questionView.js b/js/views/questionView.js index 52ee4148..be72f874 100644 --- a/js/views/questionView.js +++ b/js/views/questionView.js @@ -244,8 +244,8 @@ class QuestionView extends ComponentView { } showInstructionError() { - Adapt.trigger('questionView:showInstructionError', this); this.model.toggleClass('has-error', true); + Adapt.trigger('questionView:showInstructionError', this); } // Blank method for question to fill out when the question cannot be submitted From 61557b097c8eb49e278ae44bc0151fc6cde5166c Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Tue, 22 Oct 2024 09:05:41 -0600 Subject: [PATCH 5/6] Remove addErrorClass --- js/views/questionView.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/views/questionView.js b/js/views/questionView.js index be72f874..be6a9cd4 100644 --- a/js/views/questionView.js +++ b/js/views/questionView.js @@ -181,7 +181,6 @@ class QuestionView extends ComponentView { if (!canSubmit) { this.showInstructionError(); - this.addErrorClass(); this.onCannotSubmit(); return; } From a418933152f813bb0e72163524741c69c294c7fa Mon Sep 17 00:00:00 2001 From: Brad Simpson Date: Tue, 22 Oct 2024 12:59:01 -0600 Subject: [PATCH 6/6] Move error class assignment --- js/views/questionView.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/js/views/questionView.js b/js/views/questionView.js index be6a9cd4..1aae2cb0 100644 --- a/js/views/questionView.js +++ b/js/views/questionView.js @@ -49,7 +49,6 @@ class QuestionView extends ComponentView { preRender() { this.listenTo(this.model, { 'change:_isEnabled': this.onEnabledChanged, - 'change:_isSubmitted': this.onSubmittedChanged, 'question:refresh': this.refresh }); @@ -80,11 +79,6 @@ class QuestionView extends ComponentView { } - onSubmittedChanged(model) { - // Remove error class, if it exists - model.toggleClass('has-error', false); - } - // Used by the question to disable the question during submit and complete stages disableQuestion() {} @@ -179,6 +173,8 @@ class QuestionView extends ComponentView { // and give a blank method, onCannotSubmit to the question const canSubmit = this._runModelCompatibleFunction('canSubmit'); + this.model.toggleClass('has-error', !canSubmit); + if (!canSubmit) { this.showInstructionError(); this.onCannotSubmit(); @@ -243,7 +239,6 @@ class QuestionView extends ComponentView { } showInstructionError() { - this.model.toggleClass('has-error', true); Adapt.trigger('questionView:showInstructionError', this); }