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
Add isValidating to field state #10657
Add isValidating to field state #10657
Conversation
This branch is running in CodeSandbox. Use the links below to review this PR faster. |
Hey @bluebill1049, |
I did some adjustments to the formState validatingFields property (it uses a boolean instead of a counter now). The use of a counter here was wrong from the beginning I guess, because stapled validators shouldn't be possible. This was fixed with #10949. |
@bluebill1049 Any chance on getting a review on this? |
Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️ |
Hey @bluebill1049, I'm kindly asking again if there is anything we can do to make a review on this happen? |
Hey, Best, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff! sorry for the late review, I have been very busy with everything.
src/__tests__/useForm.test.tsx
Outdated
let formState: any; | ||
let getFieldState: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we please remove any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/__tests__/useForm.test.tsx
Outdated
let formState: any; | ||
let getFieldState: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/__tests__/useForm.test.tsx
Outdated
let getFieldState: any; | ||
let formState: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/__tests__/useForm.test.tsx
Outdated
let unregister: any; | ||
let formState: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👁️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/logic/createFormControl.ts
Outdated
const isAnyFieldValidating = Object.values( | ||
_formState.validatingFields, | ||
).some((val) => val); | ||
_proxyFormState.isValidating && | ||
_subjects.state.next({ | ||
isValidating: isAnyFieldValidating, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this can be wrapped within the _proxyFormState
check.
src/logic/createFormControl.ts
Outdated
const isAnyFieldValidating = Object.values( | ||
_formState.validatingFields, | ||
).some((val) => val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils/isEmptyObject.ts
check will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isEmptyObject is not doing what I want here. I extracted this to a util method called objectHasTruthyValue.
src/logic/createFormControl.ts
Outdated
set(_formState.validatingFields, name, isValidating); | ||
_subjects.state.next({ | ||
isValidating: value, | ||
validatingFields: _formState.validatingFields, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can move to the _updateIsValidating
function and wrapped within the proxy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored updateIsValidating and updateValidatingFields into one method and added the check for the proxyFormState.
src/logic/createFormControl.ts
Outdated
fieldNames.forEach((name) => { | ||
_updateValidatingFields(true, name); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do that within the _updateValidatingFields
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this so that _updateValidatingFields has an array of field names as its argument.
Nice thanks for the update! I will take a look at it again this weekend. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for following the code style as well. It's not the most readable but definitely save bytes for the output bundle. We can roll this out as the next feature release. Great stuff.
Todo list
|
…k-form#10657) * Add isValidating to field state * Fix type tests for isValidating field state * Adjust bundlewatch maxSize * Fix api-extractor.md merge fail * Adjust formState validatingFields property * Adjust bundlewatch maxSize * Refactoring for isValidating fieldState * Fix multi async validators behavior * Remove unnecessary explicit type definition in isValidating test * Improve _updateIsValidating method * Add proxyFormState check to updateIsValidating method --------- Co-authored-by: Beier (Bill) <bluebill1049@hotmail.com>
close #8160
This PR includes the following:
Motivation behind this is that we want to display an indicator at individual form fields when they are validating.
There was already an issue where some people requested that feature a while ago: #5744
I also already created a branch in my fork of the documentation for this feature (react-hook-form/documentation@master...pbankonier:react-hook-form-documentation:feature/fieldState_isValidating)