Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 fix #9571 validation issue with unregister input with valueAsNumber #9572

Merged
merged 1 commit into from Dec 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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