How to disable html5-validation for specific buttons in symfony 2.3

﹥>﹥吖頭↗ 提交于 2019-12-06 13:05:27

All you need to do is to add the html attribute novalidate or novalidate="novalidate" to the element. You can do this same way you would add any other attribute from either the form type of the twig template. For example:

{{ form_widget(form.add, { 'attr': {'novalidate': 'novalidate' }}) }}

Actually, reading your question again, I'm not entirely sure what sort of validation you are trying to do on a button. You have to put novalidate on all the elements that you don't want to validate.

You can also put novalidate on the form itself:

<form action="demo_form.asp" novalidate>

To disable form validation, use formnovalidate on submit button.

For example:

<div class="row">
  <input type="email">
  <input formnovalidate type="submit" value="Remove row">
</div>
<div class="row">
  ...
</div>
<input type="submit" value="Submit rows">

Note the formnovalidate is on the remove button, so even if field next to it contains invalid e-mail, it still can be removed. The real submit button does not have the formnovalidate attribute, so all e-mail must be valid before actually submitting the form.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!