Skip to content

Commit f9d3f47

Browse files
committed
MOBILE-4690 quiz: Check empty units on numerical question
1 parent fbd8fbb commit f9d3f47

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/addons/qtype/numerical/services/handlers/numerical.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,17 @@ export class AddonQtypeNumericalHandlerService implements CoreQuestionHandler {
216216
return Translate.instant('addon.qtype_numerical.invalidnumber');
217217
}
218218

219-
if (!question.parsedSettings) {
220-
if (this.hasSeparateUnitField(question)) {
221-
return Translate.instant('addon.qtype_numerical.unitnotselected');
222-
}
219+
if (this.hasSeparateUnitField(question) && !this.isValidValue(<string> answers.unit)) {
220+
return Translate.instant('addon.qtype_numerical.unitnotselected');
221+
}
223222

224-
// We cannot know if the answer should contain units or not.
223+
if (!question.parsedSettings) {
224+
// We cannot check anything else without settings.
225225
return;
226226
}
227227

228228
if (question.parsedSettings.unitdisplay !== AddonQtypeNumericalHandlerService.UNITINPUT && unit) {
229+
// There should be no units or be outside of the input, not valid.
229230
return Translate.instant('addon.qtype_numerical.invalidnumbernounit');
230231
}
231232

0 commit comments

Comments
 (0)