From 3fe4d02bc155e72734b7f50e1e84993d7933692d Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 6 Sep 2018 12:39:54 +0200 Subject: [PATCH] MOBILE-2567 quiz: Fix single multichoice without answer --- src/addon/mod/quiz/pages/player/player.scss | 4 ++++ .../qtype/multichoice/providers/handler.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/addon/mod/quiz/pages/player/player.scss b/src/addon/mod/quiz/pages/player/player.scss index 0ee54c698..5766ea400 100644 --- a/src/addon/mod/quiz/pages/player/player.scss +++ b/src/addon/mod/quiz/pages/player/player.scss @@ -7,4 +7,8 @@ ion-app.app-root page-addon-mod-quiz-player { .core-has-fixed-timer form { padding-top: 56px; } + + .toolbar-ios .bar-buttons-ios .bar-button { + @include padding-horizontal($content-padding); + } } \ No newline at end of file diff --git a/src/addon/qtype/multichoice/providers/handler.ts b/src/addon/qtype/multichoice/providers/handler.ts index 8eded4917..b543e3d97 100644 --- a/src/addon/qtype/multichoice/providers/handler.ts +++ b/src/addon/qtype/multichoice/providers/handler.ts @@ -151,4 +151,22 @@ export class AddonQtypeMultichoiceHandler implements CoreQuestionHandler { isSameResponseSingle(prevAnswers: any, newAnswers: any): boolean { return this.utils.sameAtKeyMissingIsBlank(prevAnswers, newAnswers, 'answer'); } + + /** + * Prepare and add to answers the data to send to server based in the input. Return promise if async. + * + * @param {any} question Question. + * @param {any} answers The answers retrieved from the form. Prepared answers must be stored in this object. + * @param {boolean} [offline] Whether the data should be saved in offline. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {void|Promise} Return a promise resolved when done if async, void if sync. + */ + prepareAnswers(question: any, answers: any, offline: boolean, siteId?: string): void | Promise { + if (question && !question.multi && typeof answers[question.optionsName] != 'undefined' && !answers[question.optionsName]) { + /* It's a single choice and the user hasn't answered. Delete the answer and its sequencecheck because + sending an empty string (default value) will mark the first option as selected. */ + delete answers[question.optionsName]; + delete answers[question.optionsName.replace('answer', ':sequencecheck')]; + } + } }