Skip to content

Commit

Permalink
feat: ignore minimum check when a number field is empty (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvasin authored Aug 29, 2023
1 parent 3e6f175 commit c87f837
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/lib/core/components/Form/__tests__/DynamicField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ test('Form/hooks/DynamicField', () => {

const errors = {
name: false,
'name.id': ErrorMessages.minNumber(10),
'name.name': ErrorMessages.REQUIRED,
'name.description': ErrorMessages.REQUIRED,
'name.settings': ErrorMessages.REQUIRED,
Expand Down Expand Up @@ -213,7 +212,6 @@ test('Form/hooks/DynamicField', () => {

const errors1 = {
name: false,
'name.id': ErrorMessages.minNumber(10),
'name.name': ErrorMessages.REQUIRED,
'name.description': ErrorMessages.REQUIRED,
'name.settings': ErrorMessages.REQUIRED,
Expand Down Expand Up @@ -250,7 +248,6 @@ test('Form/hooks/DynamicField', () => {

const errors2 = {
name: false,
'name.id': ErrorMessages.minNumber(10),
'name.name': ErrorMessages.REQUIRED,
'name.description': ErrorMessages.REQUIRED,
'name.settings': ErrorMessages.REQUIRED,
Expand Down Expand Up @@ -322,7 +319,7 @@ test('Form/hooks/DynamicField', () => {

const errors4 = {
name: false,
'name.id': ErrorMessages.minNumber(10),
'name.id': false,
'name.name': ErrorMessages.REQUIRED,
'name.description': ErrorMessages.REQUIRED,
'name.settings': ErrorMessages.REQUIRED,
Expand Down Expand Up @@ -372,7 +369,7 @@ test('Form/hooks/DynamicField', () => {

const errors5 = {
name: false,
'name.id': ErrorMessages.minNumber(10),
'name.id': false,
'name.name': ErrorMessages.REQUIRED,
'name.description': ErrorMessages.REQUIRED,
'name.settings': ErrorMessages.REQUIRED,
Expand Down
1 change: 1 addition & 0 deletions src/lib/kit/validators/__tests__/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('kit/validators/validators', () => {
spec.minimum = 100.5;

expect(getNumberValidator({ignoreMinimumCheck: true})(spec, '1.01')).toBe(false);
expect(validator(spec, '')).toBe(false);
expect(validator(spec, '1.01')).toBe(ErrorMessages.minNumber(spec.minimum));
expect(validator(spec, 1.01)).toBe(ErrorMessages.minNumber(spec.minimum));
expect(validator(spec, 101)).toBe(false);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/kit/validators/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export const getNumberValidator = (params: GetNumberValidatorParams = {}) => {
if (
!ignoreMinimumCheck &&
_.isNumber(spec.minimum) &&
((stringValue.length && spec.minimum > Number(stringValue)) || !stringValue.length)
stringValue.length &&
spec.minimum > Number(stringValue)
) {
return ErrorMessages.minNumber(spec.minimum);
}
Expand Down

0 comments on commit c87f837

Please sign in to comment.