How to check if a field is validated
See original GitHub issueIs your feature request related to a problem? Please describe. https://github.com/react-hook-form/react-hook-form/discussions/2633
Describe the solution you’d like https://github.com/react-hook-form/react-hook-form/discussions/2633
Describe alternatives you’ve considered
Copy-paste the code:
export function isFieldValid<T extends FieldValues>(field: keyof T, form?: UseFormMethods<T>) {
return form.formState?.dirtyFields[field] && !form.formState?.errors[field];
}
Example usage:
import { useFormContext } from 'react-hook-form';
import { isFieldValid } from '@/helpers/react-hook-form';
export function EmailInput() {
const form = useFormContext();
const isValid = isFieldValid('email', form);
return (
<div>
...
</div>
);
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How to check if a field is validated? #2633 - GitHub
Green check mark if the field is valid, red x if the field is invalid. I know how to check whether the field...
Read more >Form Field Validation with HTML (and a little Javascript)
Using the email type, we can check the validity of the form field with a javascript function called… checkValidity() . This function returns...
Read more >Data Validation – How to Check User Input on HTML Forms ...
In this example, we check for required fields using JavaScript. If a required field is not present, we use CSS to show the...
Read more >Check if a form is valid from within a form field [Django]
If you look at the flow of how forms are validated, you will see that the clean method is run if all the...
Read more >Fields and controls validation — Public web forms - Plumsail
Add validation for fields and controls¶ · Validate email address · Validate phone number · Validate ZIP code · Validate text length ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
proposal:
Personally, I don’t think that most people will understand the way you manage issues, also, I don’t the way to upvote, I am a bit confused about what I suppose to do thou.
I would recommend leveraging Projects and Issues at the same time because it is hard to follow the project management done this way.
That being said, it is your project, and I am grateful for your amazing work regardless of how you are handling the at the moment.