React hook form controller #5491
Answered
by
thanh-nguyen-95
karthiktrp102
asked this question in
General
-
Beta Was this translation helpful? Give feedback.
Answered by
thanh-nguyen-95
Jun 4, 2021
Replies: 1 comment 1 reply
-
First of all, that's not how you use
For you needs, you can use function isFirstNameOrLastNameFilled() {
const firstName= getValues('firstName')
const lastName = getValues('lastName')
const isValid = firstName || lastName
if (!isValid) return 'Your error message here'
return true
}
<Controller
name="firstName"
rules={{ validate: isFirstNameOrLastNameFilled }}
render={ /* render the input here */ }
/> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
bluebill1049
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all, that's not how you use
Controller
for custom input. Please read the documentation again:For you needs, you can use
validate
andgetValues
to validate each field. Some thing like this: