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

Using yup with onChange or onBlur mode #23

Closed
dioklecijan opened this issue May 1, 2019 · 12 comments
Closed

Using yup with onChange or onBlur mode #23

dioklecijan opened this issue May 1, 2019 · 12 comments

Comments

@dioklecijan
Copy link

Describe the bug
onChange and onBlur mode doesn't work with yup validation schema or I miss something :)

To Reproduce
Steps to reproduce the behavior:

  1. Open ValidationSchema example: https://codesandbox.io/s/928po918qr
  2. Set mode: 'onBlur:
const { register, handleSubmit, errors } = useForm({
    mode: 'onBlur',
    validationSchema: SignupSchema
  });
  1. Change the firstName and/or age fields and watch stringified errors object.

It looks like that clearing error works OK, but setting error does not.

Expected behavior
Expected error message for empty firstName field after leaving field.

Desktop (please complete the following information):

  • OS: macOS 10.14.4
  • Browser chrome, 73.0.3683.103
@bluebill1049
Copy link
Member

thanks @dioklecijan I will look into that and get it fixed :)

@bluebill1049
Copy link
Member

bluebill1049 commented May 1, 2019

@dioklecijan
Copy link
Author

Yep. Thanks!

@subvertallchris
Copy link

I'm finding that onBlur with Yup doesn't work until you submit the form once. You can see it in the codesandbox in @bluebill1049's comment above. Is this expected?

@bluebill1049
Copy link
Member

@subvertallchris which comment & can you post the link of the CSB?

@subvertallchris
Copy link

subvertallchris commented Apr 1, 2020

You can use this https://codesandbox.io/embed/react-hook-form-validationschema-vk3s4?fontsize=14&hidenavigation=1&theme=dark. It's the CSB from your very last comment before now with reValidateMode: 'onBlur'. You'll see that it doesn't run validations at all until you submit the form but then it runs correctly.

@bluebill1049
Copy link
Member

@subvertallchris i am going to sleep now, can you make sure use the latest version? in case that's the fix.

@subvertallchris
Copy link

Updated it to use the current version, which I'm also running locally -- no change. Thanks for quick reply and all your work on this library, it's excellent!

@bluebill1049
Copy link
Member

@subvertallchris that's correct behaviour for reValidateMode: "onBlur". you want to change your mode to "onBlur"

@subvertallchris
Copy link

😮!

I saw reValidationMode and assumed from the lack of plain validationMode that it handled 100% of the operation. Thanks for the clarification!

@bluebill1049
Copy link
Member

all good, sorry for the late reply. i was tired last night and went to bed.

@subvertallchris
Copy link

Oh man, nothing to apologize for! My day is just starting as yours is ending. This was a great turnaround time. FYI I've already got your library in production and it's going to be part of every form in the project, it's providing a great value already. Thank you for all your hard work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants