Skip to content

Commit

Permalink
🐞 fix #9571 validation issue with unregister input with valueAsNumber (
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Dec 11, 2022
1 parent f3f9e2d commit d4e2134
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/__tests__/logic/validateField.test.tsx
Expand Up @@ -57,6 +57,22 @@ describe('validateField', () => {
},
});

expect(
await validateField(
{
_f: {
valueAsNumber: true,
mount: true,
name: 'test',
ref: { name: 'test' },
required: 'required',
},
},
2,
false,
),
).toEqual({});

expect(
await validateField(
{
Expand Down
5 changes: 4 additions & 1 deletion src/logic/validateField.ts
Expand Up @@ -17,6 +17,7 @@ import isObject from '../utils/isObject';
import isRadioInput from '../utils/isRadioInput';
import isRegex from '../utils/isRegex';
import isString from '../utils/isString';
import isUndefined from '../utils/isUndefined';

import appendErrors from './appendErrors';
import getCheckboxValue from './getCheckboxValue';
Expand Down Expand Up @@ -61,7 +62,9 @@ export default async <T extends NativeFieldValue>(
const isCheckBox = isCheckBoxInput(ref);
const isRadioOrCheckbox = isRadio || isCheckBox;
const isEmpty =
((valueAsNumber || isFileInput(ref)) && !ref.value) ||
((valueAsNumber || isFileInput(ref)) &&
isUndefined(ref.value) &&
isUndefined(inputValue)) ||
inputValue === '' ||
(Array.isArray(inputValue) && !inputValue.length);
const appendErrorsCurry = appendErrors.bind(
Expand Down

0 comments on commit d4e2134

Please sign in to comment.