DEV Community

Discussion on: I was creating Forms the wrong way all along in React.js 🤔

Collapse
 
spotnick profile image
spotnick

Sounds legit. Not depending on a lib is always good. Can you do also dependant validation? Lets say if a=dog, b can only be "good Boy | bad Boy" ? Otherwise it has no validation.. smth like that? Is that possible with native HTML validators? I'm not experienced with that sorry if that sounds kinda stupid

Thread Thread
 
kuvambhardwaj profile image
Kuvam Bhardwaj

Dont be sorry for asking stupid questions, NEVER.
Coming to HTML-native way of validating, HTML can check for empty fields but complex validation? no, you have to implement that yourself in the onSubmit handler.

See this code : codesandbox.io/s/trusting-torvalds...
Try submitting the form without entering any value ;)

Thread Thread
 
spotnick profile image
spotnick

Thanks. Yeah I was aware of "simple" validation. Ok if I need something more complex I will continue using react-hook-form :)