diff --git a/src/app/modules/angular-slickgrid/constants.ts b/src/app/modules/angular-slickgrid/constants.ts index 131b3d884..598818b99 100644 --- a/src/app/modules/angular-slickgrid/constants.ts +++ b/src/app/modules/angular-slickgrid/constants.ts @@ -1,7 +1,8 @@ import { Locale } from './models/locale.interface'; export class Constants { - static locales: Locale = { + // English Locale texts when using only 1 Locale instead of I18N + static readonly locales: Locale = { TEXT_ALL_SELECTED: 'All Selected', TEXT_CANCEL: 'Cancel', TEXT_CLEAR_ALL_FILTERS: 'Clear all Filters', @@ -40,14 +41,20 @@ export class Constants { TEXT_TOGGLE_PRE_HEADER_ROW: 'Toggle Pre-Header Row', TEXT_X_OF_Y_SELECTED: '# of % selected', }; - static VALIDATION_REQUIRED_FIELD = 'Field is required'; - static VALIDATION_EDITOR_VALID_NUMBER = 'Please enter a valid number'; - static VALIDATION_EDITOR_VALID_INTEGER = 'Please enter a valid integer number'; - static VALIDATION_EDITOR_INTEGER_BETWEEN = 'Please enter a valid integer number between {{minValue}} and {{maxValue}}'; - static VALIDATION_EDITOR_INTEGER_MAX = 'Please enter a valid integer number that is lower than {{maxValue}}'; - static VALIDATION_EDITOR_INTEGER_MIN = 'Please enter a valid integer number that is greater than {{minValue}}'; - static VALIDATION_EDITOR_NUMBER_BETWEEN = 'Please enter a valid number between {{minValue}} and {{maxValue}}'; - static VALIDATION_EDITOR_NUMBER_MAX = 'Please enter a valid number that is lower than {{maxValue}}'; - static VALIDATION_EDITOR_NUMBER_MIN = 'Please enter a valid number that is greater than {{minValue}}'; - static VALIDATION_EDITOR_DECIMAL_BETWEEN = 'Please enter a valid number with a maximum of {{maxDecimal}} decimals'; + + // some Validation default texts + static readonly VALIDATION_REQUIRED_FIELD = 'Field is required'; + static readonly VALIDATION_EDITOR_VALID_NUMBER = 'Please enter a valid number'; + static readonly VALIDATION_EDITOR_VALID_INTEGER = 'Please enter a valid integer number'; + static readonly VALIDATION_EDITOR_INTEGER_BETWEEN = 'Please enter a valid integer number between {{minValue}} and {{maxValue}}'; + static readonly VALIDATION_EDITOR_INTEGER_MAX = 'Please enter a valid integer number that is lower than {{maxValue}}'; + static readonly VALIDATION_EDITOR_INTEGER_MAX_INCLUSIVE = 'Please enter a valid integer number that is lower than or equal to {{maxValue}}'; + static readonly VALIDATION_EDITOR_INTEGER_MIN = 'Please enter a valid integer number that is greater than {{minValue}}'; + static readonly VALIDATION_EDITOR_INTEGER_MIN_INCLUSIVE = 'Please enter a valid integer number that is greater than or equal to {{minValue}}'; + static readonly VALIDATION_EDITOR_NUMBER_BETWEEN = 'Please enter a valid number between {{minValue}} and {{maxValue}}'; + static readonly VALIDATION_EDITOR_NUMBER_MAX = 'Please enter a valid number that is lower than {{maxValue}}'; + static readonly VALIDATION_EDITOR_NUMBER_MAX_INCLUSIVE = 'Please enter a valid number that is lower than or equal to {{maxValue}}'; + static readonly VALIDATION_EDITOR_NUMBER_MIN = 'Please enter a valid number that is greater than {{minValue}}'; + static readonly VALIDATION_EDITOR_NUMBER_MIN_INCLUSIVE = 'Please enter a valid number that is greater than or equal to {{minValue}}'; + static readonly VALIDATION_EDITOR_DECIMAL_BETWEEN = 'Please enter a valid number with a maximum of {{maxDecimal}} decimals'; } diff --git a/src/app/modules/angular-slickgrid/editorValidators/floatValidator.ts b/src/app/modules/angular-slickgrid/editorValidators/floatValidator.ts index 009afb170..95d34695c 100644 --- a/src/app/modules/angular-slickgrid/editorValidators/floatValidator.ts +++ b/src/app/modules/angular-slickgrid/editorValidators/floatValidator.ts @@ -50,13 +50,15 @@ export function floatValidator(inputValue: any, options: FloatValidatorOptions): // when decimal value is bigger than 0, we only accept the decimal values as that value set // for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals isValid = false; - outputMsg = errorMsg || Constants.VALIDATION_EDITOR_NUMBER_MIN.replace(/{{minValue}}/gi, (matched) => mapValidation[matched]); + const defaultErrorMsg = operatorConditionalType === 'inclusive' ? Constants.VALIDATION_EDITOR_NUMBER_MIN_INCLUSIVE : Constants.VALIDATION_EDITOR_NUMBER_MIN; + outputMsg = errorMsg || defaultErrorMsg.replace(/{{minValue}}/gi, (matched) => mapValidation[matched]); } else if (maxValue !== undefined && floatNumber !== null && ((operatorConditionalType === 'exclusive' && floatNumber >= maxValue) || (operatorConditionalType === 'inclusive' && floatNumber > maxValue))) { // MAX VALUE ONLY // when decimal value is bigger than 0, we only accept the decimal values as that value set // for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals isValid = false; - outputMsg = errorMsg || Constants.VALIDATION_EDITOR_NUMBER_MAX.replace(/{{maxValue}}/gi, (matched) => mapValidation[matched]); + const defaultErrorMsg = operatorConditionalType === 'inclusive' ? Constants.VALIDATION_EDITOR_NUMBER_MAX_INCLUSIVE : Constants.VALIDATION_EDITOR_NUMBER_MAX; + outputMsg = errorMsg || defaultErrorMsg.replace(/{{maxValue}}/gi, (matched) => mapValidation[matched]); } else if ((decPlaces > 0 && !new RegExp(`^[-+]?(\\d*(\\.)?(\\d){0,${decPlaces}})$`).test(inputValue))) { // when decimal value is bigger than 0, we only accept the decimal values as that value set // for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals diff --git a/src/app/modules/angular-slickgrid/editorValidators/integerValidator.ts b/src/app/modules/angular-slickgrid/editorValidators/integerValidator.ts index 8c797f7df..68bbfae7d 100644 --- a/src/app/modules/angular-slickgrid/editorValidators/integerValidator.ts +++ b/src/app/modules/angular-slickgrid/editorValidators/integerValidator.ts @@ -48,13 +48,15 @@ export function integerValidator(inputValue: any, options: IntegerValidatorOptio // when decimal value is bigger than 0, we only accept the decimal values as that value set // for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals isValid = false; - outputMsg = errorMsg || Constants.VALIDATION_EDITOR_INTEGER_MIN.replace(/{{minValue}}/gi, (matched) => mapValidation[matched]); + const defaultErrorMsg = operatorConditionalType === 'inclusive' ? Constants.VALIDATION_EDITOR_INTEGER_MIN_INCLUSIVE : Constants.VALIDATION_EDITOR_INTEGER_MIN; + outputMsg = errorMsg || defaultErrorMsg.replace(/{{minValue}}/gi, (matched) => mapValidation[matched]); } else if (maxValue !== undefined && intNumber !== null && ((operatorConditionalType === 'exclusive' && intNumber >= maxValue) || (operatorConditionalType === 'inclusive' && intNumber !== null && intNumber > maxValue))) { // MAX VALUE ONLY // when decimal value is bigger than 0, we only accept the decimal values as that value set // for example if we set decimalPlaces to 2, we will only accept numbers between 0 and 2 decimals isValid = false; - outputMsg = errorMsg || Constants.VALIDATION_EDITOR_INTEGER_MAX.replace(/{{maxValue}}/gi, (matched) => mapValidation[matched]); + const defaultErrorMsg = operatorConditionalType === 'inclusive' ? Constants.VALIDATION_EDITOR_INTEGER_MAX_INCLUSIVE : Constants.VALIDATION_EDITOR_INTEGER_MAX; + outputMsg = errorMsg || defaultErrorMsg.replace(/{{maxValue}}/gi, (matched) => mapValidation[matched]); } return { valid: isValid, msg: outputMsg }; diff --git a/src/app/modules/angular-slickgrid/editors/__tests__/dualInputEditor.spec.ts b/src/app/modules/angular-slickgrid/editors/__tests__/dualInputEditor.spec.ts index c77aaa47c..9671bd9e1 100644 --- a/src/app/modules/angular-slickgrid/editors/__tests__/dualInputEditor.spec.ts +++ b/src/app/modules/angular-slickgrid/editors/__tests__/dualInputEditor.spec.ts @@ -650,6 +650,15 @@ describe('DualInputEditor', () => { editor = new DualInputEditor(editorArguments); const validation = editor.validate({ position: 'leftInput', inputValue: 10 }); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is greater than or equal to 10.2' }); + }); + + it('should return False when field is lower than a minValue defined using exclusive operator', () => { + mockColumn.internalColumnEditor.params.leftInput.minValue = 10.2; + mockColumn.internalColumnEditor.params.leftInput.operatorConditionalType = 'exclusive'; + editor = new DualInputEditor(editorArguments); + const validation = editor.validate({ position: 'leftInput', inputValue: 10 }); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is greater than 10.2' }); }); @@ -666,6 +675,15 @@ describe('DualInputEditor', () => { editor = new DualInputEditor(editorArguments); const validation = editor.validate({ position: 'leftInput', inputValue: 10.22 }); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is lower than or equal to 10.2' }); + }); + + it('should return False when field is greater than a maxValue defined using exclusive operator', () => { + mockColumn.internalColumnEditor.params.leftInput.maxValue = 10.2; + mockColumn.internalColumnEditor.params.leftInput.operatorConditionalType = 'exclusive'; + editor = new DualInputEditor(editorArguments); + const validation = editor.validate({ position: 'leftInput', inputValue: 10.22 }); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is lower than 10.2' }); }); diff --git a/src/app/modules/angular-slickgrid/editors/__tests__/floatEditor.spec.ts b/src/app/modules/angular-slickgrid/editors/__tests__/floatEditor.spec.ts index 530c3a295..122bc44bb 100644 --- a/src/app/modules/angular-slickgrid/editors/__tests__/floatEditor.spec.ts +++ b/src/app/modules/angular-slickgrid/editors/__tests__/floatEditor.spec.ts @@ -461,6 +461,15 @@ describe('FloatEditor', () => { editor = new FloatEditor(editorArguments); const validation = editor.validate(10); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is greater than or equal to 10.2' }); + }); + + it('should return False when field is lower than a minValue defined using exclusive operator', () => { + mockColumn.internalColumnEditor.minValue = 10.2; + mockColumn.internalColumnEditor.operatorConditionalType = 'exclusive'; + editor = new FloatEditor(editorArguments); + const validation = editor.validate(10); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is greater than 10.2' }); }); @@ -469,6 +478,15 @@ describe('FloatEditor', () => { editor = new FloatEditor(editorArguments); const validation = editor.validate(10.22); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is lower than or equal to 10.2' }); + }); + + it('should return False when field is greater than a maxValue defined using exclusive operator', () => { + mockColumn.internalColumnEditor.maxValue = 10.2; + mockColumn.internalColumnEditor.operatorConditionalType = 'exclusive'; + editor = new FloatEditor(editorArguments); + const validation = editor.validate(10.22); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid number that is lower than 10.2' }); }); diff --git a/src/app/modules/angular-slickgrid/editors/__tests__/integerEditor.spec.ts b/src/app/modules/angular-slickgrid/editors/__tests__/integerEditor.spec.ts index e31f377fb..90cf7d4e7 100644 --- a/src/app/modules/angular-slickgrid/editors/__tests__/integerEditor.spec.ts +++ b/src/app/modules/angular-slickgrid/editors/__tests__/integerEditor.spec.ts @@ -425,6 +425,15 @@ describe('IntegerEditor', () => { editor = new IntegerEditor(editorArguments); const validation = editor.validate(3); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid integer number that is greater than or equal to 10' }); + }); + + it('should return False when field is lower than a minValue defined using exclusive operator', () => { + mockColumn.internalColumnEditor.minValue = 10; + mockColumn.internalColumnEditor.operatorConditionalType = 'exclusive'; + editor = new IntegerEditor(editorArguments); + const validation = editor.validate(3); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid integer number that is greater than 10' }); }); @@ -433,6 +442,15 @@ describe('IntegerEditor', () => { editor = new IntegerEditor(editorArguments); const validation = editor.validate(33); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid integer number that is lower than or equal to 10' }); + }); + + it('should return False when field is greater than a maxValue defined using exclusive operator', () => { + mockColumn.internalColumnEditor.maxValue = 10; + mockColumn.internalColumnEditor.operatorConditionalType = 'exclusive'; + editor = new IntegerEditor(editorArguments); + const validation = editor.validate(33); + expect(validation).toEqual({ valid: false, msg: 'Please enter a valid integer number that is lower than 10' }); });