Skip to content

Commit 04b4465

Browse files
authored
fix(editor): float validator should accept decimal even without 0 suffix (#510)
* fix(editor): float validator should accept decimal even without 0 suffix - basically 0.3 and .3 should be both accepted, the second one wasn't and this PR fixes it
1 parent 5898c18 commit 04b4465

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/app/modules/angular-slickgrid/editorValidators/floatValidator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function floatValidator(inputValue: any, options: FloatValidatorOptions):
3535
} else if (isRequired && inputValue === '') {
3636
isValid = false;
3737
outputMsg = errorMsg || Constants.VALIDATION_REQUIRED_FIELD;
38-
} else if (inputValue !== '' && (isNaN(inputValue as number) || (decPlaces === 0 && !/^[-+]?(\d+(\.)?(\d)*)$/.test(inputValue)))) {
38+
} else if (inputValue !== '' && (isNaN(inputValue as number) || (decPlaces === 0 && !/^[-+]?(\d*(\.)?(\d)*)$/.test(inputValue)))) {
3939
// when decimal value is 0 (which is the default), we accept 0 or more decimal values
4040
isValid = false;
4141
outputMsg = errorMsg || Constants.VALIDATION_EDITOR_VALID_NUMBER;

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

+8
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ describe('FloatEditor', () => {
533533

534534
expect(validation).toEqual({ valid: true, msg: '' });
535535
});
536+
537+
it('should return True when field is required and field is a valid decimal value without 0 suffix', () => {
538+
mockColumn.internalColumnEditor.required = true;
539+
editor = new FloatEditor(editorArguments);
540+
const validation = editor.validate('.5');
541+
542+
expect(validation).toEqual({ valid: true, msg: '' });
543+
});
536544
});
537545
});
538546
});

0 commit comments

Comments
 (0)