diff --git a/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html b/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html index 1e8f391e9..88260c55d 100644 --- a/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html +++ b/src/addon/mod/assign/components/submission/addon-mod-assign-submission.html @@ -146,10 +146,10 @@ - +

{{ 'addon.mod_assign.gradeoutof' | translate: {$a: gradeInfo.grade} }}

- +

{{ 'addon.mod_assign.gradelocked' | translate }}

diff --git a/src/addon/mod/assign/components/submission/submission.ts b/src/addon/mod/assign/components/submission/submission.ts index 4910b8603..b4a66e101 100644 --- a/src/addon/mod/assign/components/submission/submission.ts +++ b/src/addon/mod/assign/components/submission/submission.ts @@ -472,8 +472,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { applyToAll: false, scale: false, lang: false, - disabled: false, - type: this.domUtils.numberInputSupportsComma() ? 'number' : 'text' + disabled: false }; this.originalGrades = { @@ -586,8 +585,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) { // If grade has been modified from gradebook, do not use offline. if (this.grade.modified < data.timemodified) { - this.grade.grade = !this.grade.scale && this.grade.type == 'text' ? - this.utils.formatFloat(data.grade) : data.grade; + this.grade.grade = !this.grade.scale ? this.utils.formatFloat(data.grade) : data.grade; this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; this.gradingColor = ''; this.originalGrades.grade = this.grade.grade; @@ -735,7 +733,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { const attemptNumber = this.userSubmission ? this.userSubmission.attemptnumber : -1, outcomes = {}, // Scale "no grade" uses -1 instead of 0. - grade = this.grade.scale && this.grade.grade == 0 ? -1 : this.utils.unformatFloat(this.grade.grade); + grade = this.grade.scale && this.grade.grade == 0 ? -1 : this.utils.unformatFloat(this.grade.grade, true); if (grade === false) { // Grade is invalid. @@ -802,8 +800,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { if (this.gradeInfo.scale) { this.grade.scale = this.utils.makeMenuFromList(this.gradeInfo.scale, this.translate.instant('core.nograde')); } else { - // If the grade uses a text input, format it. - this.grade.grade = this.grade.type == 'text' ? this.utils.formatFloat(this.grade.grade) : this.grade.grade; + // Format the grade. + this.grade.grade = this.utils.formatFloat(this.grade.grade); this.originalGrades.grade = this.grade.grade; // Get current language to format grade input field. diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index c13a41b81..979a01980 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -603,15 +603,6 @@ export class CoreDomUtilsProvider { return movedChildren; } - /** - * Check whether input number supports writing comma as a decimal separator. - * - * @return {boolean} Whether input number supports writing comma as a decimal separator. - */ - numberInputSupportsComma(): boolean { - return !this.platform.is('android') || this.platform.version().major > 5; - } - /** * Search and remove a certain element from inside another element. * diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index acaca2707..bfe707092 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -471,7 +471,7 @@ export class CoreUtilsProvider { * @return {string} Locale float. */ formatFloat(float: any): string { - if (typeof float == 'undefined' || float === null) { + if (typeof float == 'undefined' || float === null || typeof float == 'boolean') { return ''; } @@ -1168,9 +1168,10 @@ export class CoreUtilsProvider { * Based on Moodle's unformat_float function. * * @param {any} localeFloat Locale aware float representation. + * @param {boolean} [strict] If true, then check the input and return false if it is not a valid number. * @return {any} False if bad format, empty string if empty value or the parsed float if not. */ - unformatFloat(localeFloat: any): any { + unformatFloat(localeFloat: any, strict?: boolean): any { // Bad format on input type number. if (typeof localeFloat == 'undefined') { return false; @@ -1189,18 +1190,17 @@ export class CoreUtilsProvider { return ''; } - const localeSeparator = this.translate.instant('core.decsep'); - localeFloat = localeFloat.replace(' ', ''); // No spaces - those might be used as thousand separators. - localeFloat = localeFloat.replace(localeSeparator, '.'); + localeFloat = localeFloat.replace(this.translate.instant('core.decsep'), '.'); + + const parsedFloat = parseFloat(localeFloat); - localeFloat = parseFloat(localeFloat); // Bad format. - if (isNaN(localeFloat)) { + if (strict && (!isFinite(localeFloat) || isNaN(parsedFloat))) { return false; } - return localeFloat; + return parsedFloat; } /**