This wil...">

HTML5 input required - how to disable

JQuery Validate intercepts the required attribute, for example.

<input type="text" required /> 

This will force the client to validate the field. Now it is also part of the HTML5 specification and calls browsers that support it to display validation messages even if JavaScript is disabled.

In my application, I have already built a server-side check, which I am pleased with, so I want to stop this behavior. So my question is: how can you turn off this HTML5 check?

Update There seems to be some confusion, I am mostly happy with the JQuery validation interpreting this, and firing with validation is great. However, if the user has JavaScript disabled, I want the check to return to the server side check that I already wrote. However, since both JQuery Validate and HTML5 use the same label, it does not submit the form, but rather displays HTML5 validation messages that I want to disable. It makes sense?

+4
source share
2 answers

Add the novalidate parameter to the form object to stop the browser validating the form.

 <form action="test.do" novalidate> <input type="text" required /> </form> 
+10
source

HTML-compatible browsers naturally interpret this as a required field, so there really is no way to stop it. By adding this, you say it is required.

Here is an idea you could try. There is another attribute called "template" where you can provide an expression for validation. Perhaps if you accept all of this, then HTML5 validation in the browser just goes through everything and allows you to allow your jquery authentication.

 <input type="url" required pattern="*" /> 

I have not tested this, and it is a theory. If it works, then it's awesome.;)

0
source

Source: https://habr.com/ru/post/1487367/


All Articles