Skip to content

Commit

Permalink
fix #893 trigger validation (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Jan 24, 2020
1 parent ff7c70b commit 15727ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/contextTypes.ts
Expand Up @@ -90,6 +90,6 @@ export interface FormContextValues<
getValues: (payload?: { nest: boolean }) => FormValues;
handleSubmit: (
callback: OnSubmit<FormValues>,
) => (e: React.BaseSyntheticEvent) => Promise<void>;
) => (e?: React.BaseSyntheticEvent) => Promise<void>;
control: Control<FormValues>;
}
9 changes: 5 additions & 4 deletions src/useForm.ts
Expand Up @@ -234,7 +234,6 @@ export function useForm<FormValues extends FieldValues = FieldValues>({
getFieldValue(fieldsRef.current, fieldsRef.current[name]!.ref);

if (isFieldArray) {
console.log(defaultValuesRef.current);
const fieldArrayName = name.substring(0, name.indexOf('['));
isDirty = getIsFieldsDifferent(
transformToNestObject(getFieldsValues(fieldsRef.current))[
Expand Down Expand Up @@ -320,8 +319,10 @@ export function useForm<FormValues extends FieldValues = FieldValues>({

if (isArray(payload)) {
payload.forEach(name => {
if (errors[name]) {
set(errorsRef.current, name, errors[name]);
const error = get(errors, name);

if (error) {
set(errorsRef.current, name, error);
} else {
unset(errorsRef.current, [name]);
}
Expand Down Expand Up @@ -868,7 +869,7 @@ export function useForm<FormValues extends FieldValues = FieldValues>({

const handleSubmit = useCallback(
(callback: OnSubmit<FormValues>) => async (
e: React.BaseSyntheticEvent,
e?: React.BaseSyntheticEvent,
): Promise<void> => {
if (e) {
e.preventDefault();
Expand Down

0 comments on commit 15727ed

Please sign in to comment.