question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to check if a field is validated

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
bluebill1049commented, Nov 17, 2020

proposal:

<Controller 
  render={(props, { isDirty, isValid, error, isTouched } ) => {
    console.log(state)
  }}
/>
1reaction
yordiscommented, Nov 16, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found