简体   繁体   English

需要HTML5输入 - 如何禁用

[英]HTML5 input required - how to disable

JQuery Validate intercepts the required attribute eg JQuery Validate拦截所需的属性,例如

<input type="text" required />

This will force client side validation of the field which is great. 这将强制客户端验证该字段是很好的。 Now this also is part of the HTML5 spec and causes browsers that support that to show validation messages even if JavaScript is disabled. 现在,这也是HTML5规范的一部分,并使得支持该浏览器的浏览器即使禁用了JavaScript也会显示验证消息。

In my application I have already built the server side validation which I am happy with so I want to stop this behaviour. 在我的应用程序中,我已经构建了服务器端验证,我很满意,所以我想停止这种行为。 So my question is how can you disable this HTML5 form validation? 所以我的问题是如何禁用此HTML5表单验证?

Update There seems to be some confusion, basically I am happy with the JQuery validate interpreting that and the validation firing that is great. 更新似乎有一些混乱,基本上我很高兴JQuery验证解释和验证解雇是很好的。 However, should a user have JavaScript disabled I want the validation to fall back to the server side validation that I have already written. 但是,如果用户禁用了JavaScript,我希望验证能够回退到我已编写的服务器端验证。 However, because JQuery Validate and HTML5 share the same mark up it is not submitting the form but rather showing the HTML5 validation messages which is what I wish to disable. 但是,因为JQuery Validate和HTML5共享相同的标记,所以它不提交表单,而是显示我希望禁用的HTML5验证消息。 Does this make sense? 这有意义吗?

Add novalidate parameter in form object to stop browser validating the form. 在表单对象中添加novalidate参数以停止浏览器验证表单。

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

HTML5 compliant browsers will natively interpret that as a required field, so there isn't really a way to stop it. 符合HTML5标准的浏览器本身会将其解释为必填字段,因此实际上没有办法阻止它。 By adding it you are saying, this is required. 通过添加它你说,这是必需的。

Here's an idea, that you could try. 这是一个想法,你可以试试。 There is another attribute "pattern", where you can provide an expression for validation. 还有另一个属性“pattern”,您可以在其中提供用于验证的表达式。 Perhaps if you make this accept everything then the HTML5 validation from the browser will just pass everything by and still allow your jquery validation to work. 也许如果你让它接受所有内容,那么来自浏览器的HTML5验证将只传递所有内容并仍然允许你的jquery验证工作。

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

I have not tested this and it is a theory. 我没有测试过这个,这是一个理论。 If it works, then that is awesome. 如果它有效,那就太棒了。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM