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

Register by name breaks validation #61

Closed
breytex opened this issue Jun 7, 2019 · 3 comments
Closed

Register by name breaks validation #61

breytex opened this issue Jun 7, 2019 · 3 comments
Labels
question Further information is requested

Comments

@breytex
Copy link

breytex commented Jun 7, 2019

Describe the bug
I am trying to connect a SemanticUI controlled component to the hook-form lib.
I am using

  useEffect(() => {
    register({ name: "somename" }, { required: true })
  }, [])

const onChange = (e) => {
    setValue("somename", e.target.value)
  }

to connect it.

However, the validation behaves in a weird way:

  • When trying to fill out the input field in a valid way and submit, it works
  • When trying to first submit a not valid form, fill it out afterwards and submit, it still gives an validation error

To Reproduce
Minimal example:
https://codesandbox.io/s/rough-pine-p8ypz?fontsize=14

2019-06-07 11 53 48

Expected behavior
Validation should work after:

  • submitting an invalid form
  • input valid data
  • submitting again

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
@bluebill1049
Copy link
Member

bluebill1049 commented Jun 7, 2019

hey @breytex,

Thanks for the detailed issue reporting :)

because you registered that input manually instead of

<input ref={regsiter} />

so react hook form will not have the reference with the input ref when you start to type in the input, It wouldn't re-validate itself.

with setError you can set error and clear manually

const handleChange = (e) => {
  if (e.target.value) {
    setError('test');
  }
}
<input onChange={handleChange} />

or

triggerValidation({
  name: 'test',
  value: e.target.value,
})

https://codesandbox.io/s/beautiful-hertz-ert5m

@bluebill1049 bluebill1049 added the question Further information is requested label Jun 7, 2019
@bluebill1049
Copy link
Member

hey @breytex

just a quick follow up on this issue, how u doing with it?

cheers
bill

@bluebill1049
Copy link
Member

going to close this issue, for now, feel free to reopen if you still have question 👍

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

No branches or pull requests

2 participants