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.

`Controller` should also pass down validation state and errors to input-component

See original GitHub issue

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

I’m using react-native and Controller to wrap my UI-components. As far as I have understood the docs input-components and error messages are handled as two independent things. From an UI/UX perspective an input-component should represent itself its valid state, p.ex. a red border for an TextInput or a green check-mark after a valid edition. Thus a input-component could be in one of the following states:

  • untouched (with or without value)
  • positively validated (a validation was successful)
  • error (a validation failed)

The validation occurs like described for mode and reValidationMode.

Currently I could somehow pass errors from useForm down to the component, but then I need a possibility to resolve name to the associated entry (with message) in the errors object.

Currently I don’t know how to get a this-input-was-successful-validated state.

Describe the solution you’d like I suggest to add error to the props which are passed to register. error is null or an object (coming from useForm:errors). This way the input-component can access p.ex. error.message to adopt the look-and-feel of the component

I suggest to add validated to the props which are passed to register. validated is true if and only if the input was validated successfully and was not changed since then (also depends on validation mode settings).

Describe alternatives you’ve considered see above

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
moulinraphaelcommented, Nov 28, 2020

I should be awesome ! Furthermore it would be very useful to be able to watch errors as we do with values via useWatch (I have very large forms in which i wan’t to display error for each field without re-rendering the whole form)

0reactions
bluebill1049commented, Nov 20, 2020

good point @voxspox hasError 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

ControlValueAccessor with Error Validation in Angular Material
I had the same problem. I tried all and then finally could resolve using this method: I added this listener on the custom...
Read more >
Controller | React Hook Form - Simple React forms validation
Set to true if the form doesn't have any errors. setError has no effect on isValid formState, isValid will always derived via the...
Read more >
Handle form and validation with React - DEV Community ‍ ‍
Form context receives the values and changes its state to new value and pass it down to the input (controlled input). When the...
Read more >
React Hook Form: A guide with examples - LogRocket Blog
Learn all about using forms in React with React Hook Form, including how to create and validate forms — even with third-party components....
Read more >
How To Handle Form and Validation with React? - HackerNoon
We will create a Form context that will hold all the states and define ... Those will then be passed down to the...
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