Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.0] Fix for Numeric form field to allow Null min/max values in validation methods #18585

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading