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

被刻印的时光 ゝ 提交于 2019-12-08 00:16:52

问题


I have a form with three buttons. One for adding objects, one for deleting and one for editing objects.

I now want to disable html5-validation in the add-button using the new form buttons introduced in Symfony 2.3. Is this possible or do I have to create a new button type? How could I do that?


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/17068778/how-to-disable-html5-validation-for-specific-buttons-in-symfony-2-3

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