Merge pull request #1632 from dpalou/MOBILE-2743

MOBILE-2743 quiz: Fix first option selected when checking answer
main
Juan Leyva 2018-11-27 16:19:16 +01:00 committed by GitHub
commit b580aca8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -166,14 +166,17 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy {
behaviourButtonClicked(button: any): void {
// Confirm that the user really wants to do it.
this.domUtils.showConfirm(this.translate.instant('core.areyousure')).then(() => {
const modal = this.domUtils.showModalLoading('core.sending', true),
answers = this.getAnswers();
const modal = this.domUtils.showModalLoading('core.sending', true);
// Add the clicked button data.
answers[button.name] = button.value;
// Get the answers.
return this.prepareAnswers().then((answers) => {
// Behaviour checks are always in online.
return this.quizProvider.processAttempt(this.quiz, this.attempt, answers, this.preflightData).then(() => {
// Add the clicked button data.
answers[button.name] = button.value;
// Behaviour checks are always in online.
return this.quizProvider.processAttempt(this.quiz, this.attempt, answers, this.preflightData);
}).then(() => {
this.reloadNavigaton = true; // Data sent to server, navigation should be reloaded.
// Reload the current page.

View File

@ -163,10 +163,9 @@ export class AddonQtypeMultichoiceHandler implements CoreQuestionHandler {
*/
prepareAnswers(question: any, answers: any, offline: boolean, siteId?: string): void | Promise<any> {
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
/* It's a single choice and the user hasn't answered. Delete the answer 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')];
}
}
}