fix: resetField({ value: undefined }) form validity#5136
fix: resetField({ value: undefined }) form validity#5136
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: d75959f The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for vee-validate-v5 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vee-validate-docs canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where calling resetField({ value: undefined }) could leave meta.valid stuck in an invalid state even after the user enters a new valid value, by aligning useForm.resetField() behavior with resetForm() / useField.resetField().
Changes:
- Reset
pathState.validatedtofalseinsideuseForm.resetField(). - Trigger a
nextTicksilent validation (validateField(..., { mode: 'silent' })) after resetting a field to recomputepathState.validagainst the schema. - Add a regression test covering
resetFieldwith anundefinedvalue and subsequent valid input.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/vee-validate/src/useForm.ts | Resets validated and runs post-reset silent validation to keep field/form validity in sync with schema. |
| packages/vee-validate/tests/useForm.spec.ts | Adds regression coverage for issue #4996. |
| .changeset/fix-4996-resetfield-undefined.md | Adds a patch changeset entry documenting the fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
resetField({ value: undefined })no longer prevents the form from becoming valid again after entering a new valid valueuseForm.resetField()behavior withresetForm()by resetting thevalidatedflag and running a silent validation after resetRoot Cause
The
resetFieldfunction inuseForm.tswas missing two things thatresetForm(anduseField'sresetField) already did:pathState.validated = false-- Without this, the field'svalidatedflag stayedtruefrom prior validation/submission, leaving the field in an inconsistent state after reset.nextTick-- Without this, thepathState.validflag was not recalculated against the schema after the field value was reset, which could leave the form'smeta.validin an incorrect state.Test plan
resetField with undefined value should not prevent form from becoming validtrueafter reset)🤖 Generated with Claude Code