Skip to content
Discussion options

You must be logged in to vote

I believe when the input is hidden, react-hook-form still validates the input, which triggers the required rules.

You can use handleSubmit(onSuccess, onError) to check if that is the case.

I suggest using validate in this case:

<Controller
  rules={{
    validate: (value) => {
      // field is valid by default if `isRuleFile` is `false`
      if (!isRuleFile) return true

      const isValid = /* your logic here */

      if (!isValid) {
        return 'Your error message'
      }
 
      return true /* value is valid */
    }
  }}
/>

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@bluebill1049
Comment options

@novaknole
Comment options

@thanh-nguyen-95
Comment options

@novaknole
Comment options

@thanh-nguyen-95
Comment options

Answer selected by bluebill1049
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants