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

watch() called with an array returns the defaultValues for falsy values #251

Closed
dkusano opened this issue Aug 24, 2019 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@dkusano
Copy link

dkusano commented Aug 24, 2019

When watch() is called with an array of field names, it returns the defaultValues for fields their values are empty string or false. It should returns empty values, not default values.

This behavior doesn't occurs when watch() is called with single field name or no arguments.

Here is an example code.
https://codesandbox.io/s/react-hook-form-watch-defaultvalues-ucp22

@bluebill1049
Copy link
Member

When watch() is called with an array of field names, it returns the defaultValues for fields their values are empty string or false.

This is the expected behavior.

The example you share they have the same output.

watch array: {"name":"default name","agree":true}

watch all: {"name":"default name","agree":true}

@dkusano
Copy link
Author

dkusano commented Aug 24, 2019

I'm sorry I didn't make it clear enough.

In the example, when you input empty string and checkbox off, watch(["name", "agree"]) and watch() behave different.

watch array: {"name":"default name","agree":true}

watch all: {"name":"","agree":false}

@bluebill1049 bluebill1049 added the bug Something isn't working label Aug 24, 2019
@bluebill1049 bluebill1049 self-assigned this Aug 24, 2019
bluebill1049 added a commit that referenced this issue Aug 24, 2019
@bluebill1049
Copy link
Member

thanks, I have patched the bug: you can test out in this beta version: react-hook-form@3.22.2-beta.8

@dkusano
Copy link
Author

dkusano commented Aug 24, 2019

react-hook-form@3.22.2-beta.8 works fine in my project. Thank you!

@bluebill1049
Copy link
Member

Thanks we will release the patch soon.

bluebill1049 added a commit that referenced this issue Aug 24, 2019
* close issue on #251

* remove comments

* add unit test for isSameError
@bluebill1049 bluebill1049 added this to In progress in React Hook Form Aug 26, 2019
@bluebill1049 bluebill1049 moved this from In progress to Done in React Hook Form Aug 26, 2019
@bluebill1049
Copy link
Member

the patch has been released, please close this issue if works fine :)

@bluebill1049 bluebill1049 removed their assignment Aug 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants