Skip to content

Commit

Permalink
fix(editor): float validator should accept decimal even without 0 suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding-SE committed Jun 25, 2020
1 parent e63faad commit 87808ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/common/src/editorValidators/floatValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function floatValidator(inputValue: any, options: FloatValidatorOptions):
} else if (isRequired && inputValue === '') {
isValid = false;
outputMsg = errorMsg || Constants.VALIDATION_REQUIRED_FIELD;
} else if (inputValue !== '' && (isNaN(inputValue as number) || (decPlaces === 0 && !/^[-+]?(\d+(\.)?(\d)*)$/.test(inputValue)))) {
} else if (inputValue !== '' && (isNaN(inputValue as number) || (decPlaces === 0 && !/^[-+]?(\d*(\.)?(\d)*)$/.test(inputValue)))) {
// when decimal value is 0 (which is the default), we accept 0 or more decimal values
isValid = false;
outputMsg = errorMsg || Constants.VALIDATION_EDITOR_VALID_NUMBER;
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/editors/__tests__/floatEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ describe('FloatEditor', () => {

expect(validation).toEqual({ valid: true, msg: '' });
});

it('should return True when field is required and field is a valid decimal value without 0 suffix', () => {
mockColumn.internalColumnEditor.required = true;
editor = new FloatEditor(editorArguments);
const validation = editor.validate('.5');

expect(validation).toEqual({ valid: true, msg: '' });
});
});
});
});
Binary file not shown.

0 comments on commit 87808ce

Please sign in to comment.