material-ui-currency-textfield icon indicating copy to clipboard operation
material-ui-currency-textfield copied to clipboard

Issue working with react-hook-form validations

Open vikikamath opened this issue 4 years ago • 1 comments

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>

vikikamath avatar May 05 '20 01:05 vikikamath

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.

moisesbaddini avatar Mar 06 '21 01:03 moisesbaddini