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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): radio input validation is incorrect when validateMode is i… #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/core/src/composables/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,14 @@ export function useForm<
}
};

const handleChange: FormEventHandler['handleChange'] = () => {
if (validateTiming.value === 'change') {
const handleChange: FormEventHandler['handleChange'] = (e) => {
if (validateTiming.value === 'change' || isRadioOrCheckbox(e.target)) {
runAllValidateHandler(state.values);
}
};

const handleInput: FormEventHandler['handleInput'] = () => {
if (validateTiming.value === 'input') {
const handleInput: FormEventHandler['handleInput'] = (e) => {
if (validateTiming.value === 'input' && !isRadioOrCheckbox(e.target)) {
runAllValidateHandler(state.values);
}
};
Expand Down Expand Up @@ -697,3 +697,12 @@ function arrayMerge<T extends any[]>(target: T, source: T, options: any) {
});
return destination;
}

function isRadioOrCheckbox(
target: EventTarget | null,
): target is HTMLInputElement {
if (!target || !(target instanceof HTMLInputElement)) {
return false;
}
return target.type === 'radio' || target.type === 'checkbox';
}
8 changes: 4 additions & 4 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export interface FormState<Values extends FormValues> {

export interface FormEventHandler<S = string> {
handleBlur: (event: Event | S, name?: S) => void;
handleChange: () => void;
handleInput: () => void;
handleChange: (event: Event) => void;
handleInput: (event: Event) => void;
}

export interface FieldRegisterOptions<Values> {
Expand Down Expand Up @@ -152,8 +152,8 @@ export interface UseFormReturn<Values extends FormValues> {
export type FieldAttrs = {
name: string;
onBlur: (event: Event) => void;
onChange: () => void;
onInput: () => void;
onChange: (event: Event) => void;
onInput: (event: Event) => void;
};

export type FieldMeta<Value> = {
Expand Down
Loading