Skip to content

Commit

Permalink
Fix for Numeric form field to allow Null min/max values in validation…
Browse files Browse the repository at this point in the history
… methods
  • Loading branch information
hujambo-dunia committed Jul 22, 2024
1 parent d3fb3fd commit c70c9c4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client/src/components/Form/Elements/FormNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ export default {
type: [Number, String],
required: false,
default: undefined,
validator: (prop) => typeof prop == "number" || prop === null,
},
max: {
type: [Number, String],
required: false,
default: undefined,
validator: (prop) => typeof prop == "number" || prop === null,
},
workflowBuildingMode: {
type: Boolean,
Expand Down Expand Up @@ -74,7 +76,7 @@ export default {
return this.workflowBuildingMode ? "text" : "number";
},
isRangeValid() {
return !isNaN(this.min) && !isNaN(this.max) && this.max > this.min;
return typeof this.min == "number" && typeof this.max == "number" && this.max > this.min;
},
isInteger() {
return this.type.toLowerCase() === "integer";
Expand Down Expand Up @@ -124,10 +126,15 @@ export default {
}
},
isOutOfRange(value) {
return this.isRangeValid && (value > this.max || value < this.min);
/* If value=null, then value is within range. */
return (
(typeof this.max == "number" && value > this.max) || (typeof this.min == "number" && value < this.min)
);
},
showOutOfRangeWarning(value) {
const warningMessage = `${value} is out of ${this.min} - ${this.max} range!`;
const rangeDetail =
typeof this.max == "number" && value > this.max ? `${value} > ${this.max}` : `${value} < ${this.min}`;
const warningMessage = `${value} is out of range! (${rangeDetail})`;
this.showAlert(warningMessage);
},
resetAlert() {
Expand Down

0 comments on commit c70c9c4

Please sign in to comment.