From 4e98e6588b414a309d8f1c8939b8d6ff0fc2078c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 18 Apr 2019 12:26:00 +0200 Subject: [PATCH] MOBILE-2966 quiz: Clear answer in multiple choice single answer --- scripts/langindex.json | 1 + src/addon/mod/quiz/lang/en.json | 1 + .../multichoice/component/addon-qtype-multichoice.html | 3 +++ src/addon/qtype/multichoice/component/multichoice.ts | 7 +++++++ src/assets/lang/en.json | 1 + src/core/question/classes/base-question-component.ts | 4 ++++ 6 files changed, 17 insertions(+) diff --git a/scripts/langindex.json b/scripts/langindex.json index 7d6305fb2..2f31199ff 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -637,6 +637,7 @@ "addon.mod_quiz.attemptquiznow": "quiz", "addon.mod_quiz.attemptstate": "quiz", "addon.mod_quiz.cannotsubmitquizdueto": "local_moodlemobileapp", + "addon.mod_quiz.clearchoice": "qtype_multichoice", "addon.mod_quiz.comment": "quiz", "addon.mod_quiz.completedon": "quiz", "addon.mod_quiz.confirmclose": "quiz", diff --git a/src/addon/mod/quiz/lang/en.json b/src/addon/mod/quiz/lang/en.json index 18a699dda..c5be9879f 100644 --- a/src/addon/mod/quiz/lang/en.json +++ b/src/addon/mod/quiz/lang/en.json @@ -6,6 +6,7 @@ "attemptquiznow": "Attempt quiz now", "attemptstate": "State", "cannotsubmitquizdueto": "This quiz attempt cannot be submitted for the following reasons:", + "clearchoice": "Clear my choice", "comment": "Comment", "completedon": "Completed on", "confirmclose": "Once you submit, you will no longer be able to change your answers for this attempt.", diff --git a/src/addon/qtype/multichoice/component/addon-qtype-multichoice.html b/src/addon/qtype/multichoice/component/addon-qtype-multichoice.html index c41b376b9..56ac05cc3 100644 --- a/src/addon/qtype/multichoice/component/addon-qtype-multichoice.html +++ b/src/addon/qtype/multichoice/component/addon-qtype-multichoice.html @@ -32,6 +32,9 @@ +
+ +
diff --git a/src/addon/qtype/multichoice/component/multichoice.ts b/src/addon/qtype/multichoice/component/multichoice.ts index ec23880d5..e481c0f2f 100644 --- a/src/addon/qtype/multichoice/component/multichoice.ts +++ b/src/addon/qtype/multichoice/component/multichoice.ts @@ -35,4 +35,11 @@ export class AddonQtypeMultichoiceComponent extends CoreQuestionBaseComponent im ngOnInit(): void { this.initMultichoiceComponent(); } + + /** + * Clear selected choices. + */ + clear(): void { + this.question.singleChoiceModel = null; + } } diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 9142565fb..93ba504e9 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -637,6 +637,7 @@ "addon.mod_quiz.attemptquiznow": "Attempt quiz now", "addon.mod_quiz.attemptstate": "State", "addon.mod_quiz.cannotsubmitquizdueto": "This quiz attempt cannot be submitted for the following reasons:", + "addon.mod_quiz.clearchoice": "Clear my choice", "addon.mod_quiz.comment": "Comment", "addon.mod_quiz.completedon": "Completed on", "addon.mod_quiz.confirmclose": "Once you submit, you will no longer be able to change your answers for this attempt.", diff --git a/src/core/question/classes/base-question-component.ts b/src/core/question/classes/base-question-component.ts index 1a1dfafa0..c20654f32 100644 --- a/src/core/question/classes/base-question-component.ts +++ b/src/core/question/classes/base-question-component.ts @@ -448,6 +448,8 @@ export class CoreQuestionBaseComponent { this.question.options = []; + this.question.disabled = true; + for (const i in options) { const element = options[i], option: any = { @@ -461,6 +463,8 @@ export class CoreQuestionBaseComponent { this.question.optionsName = option.name; + this.question.disabled = this.question.disabled && element.disabled; + // Get the label with the question text. const label = questionEl.querySelector('label[for="' + option.id + '"]'); if (label) {