Reac Hook Form - Submit button only activates when I press tab or click off inputs

Asked

Viewed 25 times

0

Even by entering the password it only activates the send button when I click out of the input or tab. Why is this happening? How can I correct?

const {register, handleSubmit, formState:{errors, isValid} } = useForm({mode:"all",});

<input 
  {...register("password", {
    required: "Insira sua senha",
  })}                        
  type="password"
  id="password"
  name="password" 
  placeholder="*********" 
  value={password}
  onChange={text => setPassword(text.target.value)}
/> 
<button
  disabled={!isValid}
  type="submit">
  Enviar
</button>
  • Try using onChange instead of all in the mode

  • 1

    when I remove the value lines and onChange the input works right. but I need to use them in that input.

  • 1

    Ah, you’re squabbling with the library about who controls the input... Let the library take care of that and get the value with watch or getValues, depending on your need. If you only need the value in Ubmit, the handleSubmit passes as argument for its function

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.