如何在Symfony 2.3中为特定按钮禁用html5-validation [英] How to disable html5-validation for specific buttons in symfony 2.3

查看:77
本文介绍了如何在Symfony 2.3中为特定按钮禁用html5-validation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有三个按钮的表格.一种用于添加对象,一种用于删除,另一种用于编辑对象.

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

我现在想使用Symfony 2.3中引入的新表单按钮在添加按钮中禁用html5-validation.这可能吗,还是我必须创建一个新的按钮类型?我该怎么办?

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?

推荐答案

您需要做的就是向元素添加html属性novalidate或novalidate ="novalidate".您可以使用相同的方法,从树枝模板的表单类型中添加任何其他属性.例如:

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' }}) }}

实际上,再次阅读您的问题,我不太确定您要在按钮上进行哪种验证.您必须在所有不想验证的元素上添加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.

您还可以在表单本身上添加novalidate:

You can also put novalidate on the form itself:

<form action="demo_form.asp" novalidate>

这篇关于如何在Symfony 2.3中为特定按钮禁用html5-validation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆