Thursday, December 21, 2017

novalidate keyword in HTML

W3 schools has this example:

<form action="/action_page.php" novalidate>
   E-mail: <input type="email" name="user_email">
   <input type="submit">
</form>

 
 

...so it goes at the form tag. The description I find online is that this disables the "browser's native form validation" and yes that is a thing even if the W3 schools example explains it poorly. Perhaps a better example would be:

<form action="/action_page.php" novalidate>
   E-mail: <input type="email" name="user_email" required>
   <input type="submit">
</form>

 
 

This touches on the required keyword which might otherwise force you to put something in the user_email field before you may submit the form. In the case of the second example though, the novalidate keyword should sidestep the required keyword. What this does not do is sidestep ASP.NET MVC validations or your validations in JavaScript. My head was about to explode when I first saw this thing because I didn't get how it could possibly work, but now I understand that it is merely of limited scope. I didn't even know about the goofy native validations. Who would rely on those?

No comments:

Post a Comment