Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
29 changes: 18 additions & 11 deletions src/app/modules/angular-slickgrid/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});

Expand All @@ -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' });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});

Expand All @@ -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' });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});

Expand All @@ -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' });
});

Expand Down