Skip to content
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

How to check if a field is validated #3457

Closed
yordis opened this issue Nov 15, 2020 · 10 comments
Closed

How to check if a field is validated #3457

yordis opened this issue Nov 15, 2020 · 10 comments

Comments

@yordis
Copy link

yordis commented Nov 15, 2020

Is your feature request related to a problem? Please describe.
#2633

Describe the solution you'd like
#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>
  );
}
@bluebill1049 bluebill1049 added feature request request a feature to be added waiting-up-vote Waiting for votes from the community. labels Nov 15, 2020
@bluebill1049 bluebill1049 added this to Pending Feature Requests in React Hook Form Nov 15, 2020
@bluebill1049
Copy link
Member

Thanks 👍 will keep an eye on this and pinged to the board.

@bluebill1049
Copy link
Member

related #3434

@yordis
Copy link
Author

yordis commented Nov 16, 2020

@bluebill1049 wouldn't be better to keep the issue open? Where do I suppose to subscribe to changes related to this?

@bluebill1049
Copy link
Member

I keep a list of all feature requests open here: #1981 issues are for tracking actual issues. you can view them there: https://github.com/react-hook-form/react-hook-form/projects/1

@yordis
Copy link
Author

yordis commented 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.

@bluebill1049
Copy link
Member

Thanks, @yordis for your feedback and understanding. I do ping the feature request at the issues board.

Screen Shot 2020-11-17 at 9 38 35 am

Honestly, I am one man who tries to maintain the project here, so this way works for me over the year, so I can focus on the issues and keep away those features in separate sections instead of issues. Hope you understand 🙏

@bluebill1049 bluebill1049 moved this from Pending Feature Requests to API proposal in React Hook Form Nov 17, 2020
@bluebill1049
Copy link
Member

proposal:

<Controller 
  render={(props, { isDirty, isValid, error, isTouched } ) => {
    console.log(state)
  }}
/>

@yordis
Copy link
Author

yordis commented Nov 17, 2020

LETS GOOO

@bluebill1049 bluebill1049 removed the waiting-up-vote Waiting for votes from the community. label Nov 21, 2020
@bluebill1049 bluebill1049 moved this from API proposal to In progress in React Hook Form Nov 28, 2020
@iduuck
Copy link

iduuck commented Dec 6, 2020

Would love to get this done in an PR. However, I am not sure if this is already being implemented, since it is on “In Progress”.

Also the proposed API is not working for me, since “state” is not defined?

@bluebill1049
Copy link
Member

@iduuck it's in RFC: #3487

@bluebill1049 bluebill1049 moved this from In progress to Done in React Hook Form Dec 11, 2020
@bluebill1049 bluebill1049 removed the feature request request a feature to be added label Dec 11, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Development

No branches or pull requests

3 participants