Skip to content

Commit

Permalink
Add error/success message customization
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipAB committed Apr 10, 2024
1 parent 7fda2a5 commit 49b6f3c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/quiz/QuestionParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export interface QuestionParams {
helperText: string;
questionType: string;
validation: string;
successMsg?: string;
errorMsg?: string;
successMsg: string;
errorMsg: string;
}
4 changes: 2 additions & 2 deletions src/app/quiz/quiz-body.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*ngIf="validationEnabled && isSubmitted && !isValid"
>
<clr-alert-item>
<span class="alert-text"> Incorrect Answer! </span>
<span class="alert-text">{{ errMsg }}</span>
</clr-alert-item>
</clr-alert>
<clr-alert
Expand All @@ -17,7 +17,7 @@
*ngIf="validationEnabled && isSubmitted && isValid"
>
<clr-alert-item>
<span class="alert-text"> Correct Answer! </span>
<span class="alert-text">{{ successMsg }}</span>
</clr-alert-item>
</clr-alert>
</ng-container>
4 changes: 4 additions & 0 deletions src/app/quiz/quiz-body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class QuizBodyComponent {
public isSubmitted: boolean;
@Input()
public validationEnabled: boolean;
@Input()

Check failure on line 18 in src/app/quiz/quiz-body.component.ts

View workflow job for this annotation

GitHub Actions / Build

Type string trivially inferred from a string literal, remove type annotation
public errMsg: string = 'Incorrect Answer!';
@Input()

Check failure on line 20 in src/app/quiz/quiz-body.component.ts

View workflow job for this annotation

GitHub Actions / Build

Type string trivially inferred from a string literal, remove type annotation
public successMsg: string = 'Correct Answer!';
}
2 changes: 2 additions & 0 deletions src/app/quiz/quiz-checkbox.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
[isValid]="validSubmission"
[isSubmitted]="isSubmitted"
[validationEnabled]="validationEnabled"
[errMsg]="errMsg"
[successMsg]="successMsg"
></quiz-body>
</form>
4 changes: 4 additions & 0 deletions src/app/quiz/quiz-checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class QuizCheckboxComponent implements OnInit {
public title: string;
@Input()
public validation: string;
@Input()
public errMsg: string;
@Input()
public successMsg: string;

@ViewChild(ClrForm, { static: true })
clrForm: ClrForm;
Expand Down
2 changes: 2 additions & 0 deletions src/app/quiz/quiz-radio.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
[isValid]="validSubmission"
[isSubmitted]="isSubmitted"
[validationEnabled]="validationEnabled"
[errMsg]="errMsg"
[successMsg]="successMsg"
></quiz-body>
</form>
4 changes: 4 additions & 0 deletions src/app/quiz/quiz-radio.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class QuizRadioComponent implements OnInit {
public title: string;
@Input()
public validation: string;
@Input()
public errMsg: string;
@Input()
public successMsg: string;

@ViewChild(ClrForm, { static: true })
clrForm: ClrForm;
Expand Down
4 changes: 4 additions & 0 deletions src/app/quiz/quiz.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ <h5 class="quiz-title">{{ quizTitle }}</h5>
[helperText]="questionParams[i].helperText"
[title]="questionParams[i].questionTitle"
[validation]="questionParams[i].validation"
[errMsg]="questionParams[i].errorMsg"
[successMsg]="questionParams[i].successMsg"
></quiz-checkbox>
<quiz-radio #quizRadio *ngIf="getQuestionType(question, questionParams[i].questionType) === 'radio'"
[options]="getOptions(question)"
[helperText]="questionParams[i].helperText"
[title]="questionParams[i].questionTitle"
[validation]="questionParams[i].validation"
[errMsg]="questionParams[i].errorMsg"
[successMsg]="questionParams[i].successMsg"
></quiz-radio>
</ng-container>
<button
Expand Down
8 changes: 6 additions & 2 deletions src/app/quiz/quiz.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class QuizComponent implements OnInit {
let helperText: string;
let questionType: string;
let validation: string;
let successMsg: string | undefined;
let errorMsg: string | undefined;
let successMsg: string;
let errorMsg: string;
if (/-\$1-:\s/.test(question)) {
questionTitle =
question
Expand Down Expand Up @@ -112,13 +112,17 @@ export class QuizComponent implements OnInit {
.split('-$5-: ')
.pop()
?.split(/(\n-\$\d-:\s)|(\n-\s)/)[0] ?? '';
} else {
successMsg = "Correct Answer!"
}
if (/-\$6-:\s/.test(question)) {
errorMsg =
question
.split('-$6-: ')
.pop()
?.split(/(\n-\$\d-:\s)|(\n-\s)/)[0] ?? '';
} else {
errorMsg = "Incorrect Answer!"
}

return {
Expand Down

0 comments on commit 49b6f3c

Please sign in to comment.