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

Issue working with react-hook-form validations #23

Open
vikikamath opened this issue May 5, 2020 · 1 comment
Open

Issue working with react-hook-form validations #23

vikikamath opened this issue May 5, 2020 · 1 comment

Comments

@vikikamath
Copy link

The error validations do not work very well with react-hook-form
On submit, the error is not displayed when validation fails

Relevant CodeSandbox

Using @material-ui input with input adornments however works:

<FormControl variant="outlined" className={classes.formControl}>
 <InputLabel htmlFor="amount">Amount</InputLabel>
   <OutlinedInput
                 inputRef={register({
                   validate: (value) =>
                     value && typeof value === "number" && value > 0,
                 })}
                 name="amount"
                 value={amount}
                 onChange={(e) => setAmount(e.target.value)}
                 startAdornment={
                   <InputAdornment position="start">$</InputAdornment>
                 }
                 labelWidth={60}
               />
               {errors.amount && (
                 <FormHelperText error variant="outlined">
                   Please enter an amount
                 </FormHelperText>
               )}
             </FormControl>
@moisesbaddini
Copy link

moisesbaddini commented Mar 6, 2021

I have a similar problem, and I noticed that it is missing the name in the component, although you have filled in the attribute (with "amount").

Please note the Sandbox console that you attached above, react-hook-forms cannot register an unnamed component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants