🐞 fix: pass options parameter through setValues to enable validation#13457
Merged
bluebill1049 merged 2 commits intoMay 19, 2026
Merged
Conversation
- Accept options parameter in setValues function - Pass options to _setValue for each field - Call _setValid() when shouldValidate is true - Add tests for shouldValidate, shouldDirty, and shouldTouch options This fixes the issue where setValues with shouldValidate: true was not updating the isValid form state.
- Test error clearing when revalidating with valid values - Test multiple fields validation with setValues - Test that validation is not triggered without shouldValidate option - Test pattern validation (email), minLength, min, and required rules These tests verify that setValues with shouldValidate: true properly clears errors and updates isValid state when fields become valid. Signed-off-by: Alexandre Philibeaux <aphilibeaux@scaleway.com>
446cc22 to
e0ffb13
Compare
1 task
bluebill1049
approved these changes
May 19, 2026
Member
|
I didn't think user would need that options, but then i check the doc... i did put all the options there https://react-hook-form.com/docs/useform/setvalues could you include |
Member
|
nvm you did. ty |
Contributor
Author
|
@bluebill1049 actually i still have a bug on this test on my side, and my Submit button is based on isValid from the form which is not revalidate after the setValues. From your point of view, isValid should be recompute anyway ? |
Member
|
oh i think missing the subscription update there. |
Member
|
let me check it out. |
Member
|
hmm should just worked, i wrote a test and it pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the issue where
setValueswas not respecting theoptionsparameter, specificallyshouldValidate,shouldDirty, andshouldTouch.Problem
When calling:
The
optionsparameter was being ignored, causing:isValidform state not to updatedirtyFieldsandtouchedFieldsnot to updateSolution
Modified the
setValuesfunction to:optionsparameter (already defined in the type)_setValuefunction for each field_setValid()whenshouldValidate: trueto recalculate form validityTests (
src/__tests__/useForm/setValues.test.tsx)Added 3 comprehensive tests:
shouldValidate: trueRelated Issues
Checklist