Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 3fb5dab

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
refactor(editor): should compare against both min/max values
1 parent 8631c5c commit 3fb5dab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/app/modules/angular-slickgrid/editors/floatEditor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,29 @@ export class FloatEditor implements Editor {
137137
if (!validationResults.valid) {
138138
return validationResults;
139139
}
140-
} else if (isNaN(elmValue as number) || (decPlaces === 0 && !/^(\d+(\.)?(\d)*)$/.test(elmValue))) {
140+
} else if (isNaN(elmValue as number) || (decPlaces === 0 && !/^[-+]?(\d+(\.)?(\d)*)$/.test(elmValue))) {
141141
// when decimal value is 0 (which is the default), we accept 0 or more decimal values
142142
return {
143143
valid: false,
144144
msg: errorMsg || Constants.VALIDATION_EDITOR_VALID_NUMBER
145145
};
146-
} else if (minValue !== undefined && minValue !== undefined && (floatNumber < minValue || floatNumber > maxValue)) {
146+
} else if (minValue !== undefined && maxValue !== undefined && floatNumber !== null && (floatNumber < minValue || floatNumber > maxValue)) {
147147
// MIN & MAX Values provided
148148
// when decimal value is bigger than 0, we only accept the decimal values as that value set
149149
// for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals
150150
return {
151151
valid: false,
152152
msg: errorMsg || Constants.VALIDATION_EDITOR_NUMBER_BETWEEN.replace(/{{minValue}}|{{maxValue}}/gi, (matched) => mapValidation[matched])
153153
};
154-
} else if (minValue !== undefined && floatNumber <= minValue) {
154+
} else if (minValue !== undefined && floatNumber !== null && floatNumber <= minValue) {
155155
// MIN VALUE ONLY
156156
// when decimal value is bigger than 0, we only accept the decimal values as that value set
157157
// for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals
158158
return {
159159
valid: false,
160160
msg: errorMsg || Constants.VALIDATION_EDITOR_NUMBER_MIN.replace(/{{minValue}}/gi, (matched) => mapValidation[matched])
161161
};
162-
} else if (maxValue !== undefined && floatNumber >= maxValue) {
162+
} else if (maxValue !== undefined && floatNumber !== null && floatNumber >= maxValue) {
163163
// MAX VALUE ONLY
164164
// when decimal value is bigger than 0, we only accept the decimal values as that value set
165165
// for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals

0 commit comments

Comments
 (0)