Skip to content

e.setCustomValidity() is not a function -- non-native input elements #10587

Answered by leapful
jviall asked this question in Q&A
Discussion options

You must be logged in to vote

@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:

elem.setCustomValidity = elem.setCustomValidity || noop;
elem.reportValidity = elem.reportValidity || noop;

Working demo: https://codesandbox.io/s/rhf-native-validation-w-zod--downshift-select-forked-8wsczg?file=/src/App.tsx

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jviall
Comment options

Answer selected by jviall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants
Converted from issue

This discussion was converted from issue #10570 on June 24, 2023 10:21.