-
Version Number7.44.2 Codesandbox/Expo snackhttps://codesandbox.io/s/rhf-native-validation-w-zod--downshift-select-qwj82y Steps to reproduce
Behavior: Expected behaviourI'd expect that simply nothing happens in this case. It feels like a valid use case to want to use native validation for inputs that can support it, and for ones that cannot that it is simply skipped. It seems like the issue could be fixed by adding a check for the presence of If you're open to a PR, I can put one up! Aside from this, I'm also working to see how I can modify Downshift's recommended implementation of their What browsers are you seeing the problem on?Chrome Relevant log outputUncaught (in promise) TypeError: e.setCustomValidity is not a function
at Object.setCustomValidity (index.cjs.js:1:4509)
at e (resolvers.js:1:198)
at t (resolvers.js:1:342)
at i (resolvers.js:1:431)
at exports.toNestError (resolvers.js:1:500)
at eval (zod.js:1:1064)
at async eval (index.cjs.js:1:18223) Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
I don't think this will work if you applied to a |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 Correct, that's why the error In my codesandbox, there are two other native inputs. When |
Beta Was this translation helpful? Give feedback.
-
I think this will work if we simply checked for
react-hook-form/src/useController.ts Lines 147 to 149 in a4be81f |
Beta Was this translation helpful? Give feedback.
-
Yes, we can do that, but it's pretty much trying to shallow the error, the question is why should we support non-input elements in the first place? This would probably create inconsistent and unexpected behavior. If it's not going to work, it's probably better to throw an error early than ship it to production. |
Beta Was this translation helpful? Give feedback.
-
If you really want to use native validation with a non native input element, like div element, you can apply duck typing for the div element with the required methods. For example:
Working demo: https://codesandbox.io/s/rhf-native-validation-w-zod--downshift-select-forked-8wsczg?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
@jviall
If you really want to use native validation with a non native input element, like div element, you can apply duck typing for the div element with the required methods.
For example:
Working demo: https://codesandbox.io/s/rhf-native-validation-w-zod--downshift-select-forked-8wsczg?file=/src/App.tsx