Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Add "has-error" class for use with question components (fixes #594) #595

Merged
merged 7 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion js/views/questionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
swashbuck marked this conversation as resolved.
Show resolved Hide resolved
this.listenTo(this.model, 'question:refresh', this.refresh);

// Checks to see if the question should be reset on revisit
Expand Down Expand Up @@ -79,6 +79,11 @@ class QuestionView extends ComponentView {

}

onSubmittedChanged(model) {
// Remove error class, if it exists
model.toggleClass('has-error', false);
swashbuck marked this conversation as resolved.
Show resolved Hide resolved
}

// Used by the question to disable the question during submit and complete stages
disableQuestion() {}

Expand Down Expand Up @@ -175,6 +180,7 @@ class QuestionView extends ComponentView {

if (!canSubmit) {
this.showInstructionError();
this.addErrorClass();
oliverfoster marked this conversation as resolved.
Show resolved Hide resolved
this.onCannotSubmit();
return;
}
Expand Down Expand Up @@ -240,6 +246,10 @@ class QuestionView extends ComponentView {
Adapt.trigger('questionView:showInstructionError', this);
}

addErrorClass() {
this.model.toggleClass('has-error', true);
}

swashbuck marked this conversation as resolved.
Show resolved Hide resolved
// Blank method for question to fill out when the question cannot be submitted
onCannotSubmit() {}

Expand Down
Loading