Skip to content

Commit

Permalink
fix: handle pending validation runs during field unmounting
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Mar 3, 2021
1 parent 89825cb commit ef5a7cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/vee-validate/src/useField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function useField<TValue = unknown>(
bails,
});
} else {
result = (await form.validateSchema())[unref(name)];
result = (await form.validateSchema())[unref(name)] ?? { valid: true, errors: [] };
}

meta.pending = false;
Expand Down
6 changes: 3 additions & 3 deletions packages/vee-validate/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,16 @@ async function validateYupSchema<TValues>(
return err.inner || [];
});

const fields = form.fieldsById.value;
const fieldsById = form.fieldsById.value || {};
const errorsByPath = errors.reduce((acc, err) => {
acc[err.path as keyof TValues] = err;

return acc;
}, {} as Record<keyof TValues, ValidationError>);

// Aggregates the validation result
const aggregatedResult = keysOf(fields).reduce((result: Record<keyof TValues, ValidationResult>, fieldId) => {
const field: PrivateFieldComposite | PrivateFieldComposite[] = fields[fieldId];
const aggregatedResult = keysOf(fieldsById).reduce((result: Record<keyof TValues, ValidationResult>, fieldId) => {
const field: PrivateFieldComposite | PrivateFieldComposite[] = fieldsById[fieldId];
const messages = (errorsByPath[fieldId] || { errors: [] }).errors;
const fieldResult = {
errors: messages,
Expand Down

0 comments on commit ef5a7cc

Please sign in to comment.