symfony2:试图添加一个类型=“数字"属性到表单域 [英] symfony2: trying to add a type="number" attribute to a form field
本文介绍了symfony2:试图添加一个类型=“数字"属性到表单域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个字段,
->add('number', 'number', array(
'label' => false,
'attr' => array('class' => 'producto', 'type' => 'number')))
我希望添加一个 type="number"
属性,用向下/向上的小箭头增加和减少里面的数字,但我得到了一个带有 type="text" 属性的输入:
I expected a type="number"
attribute to be added, increase and decrease the number inside with the little arrows down/up, but I get an input with type="text" attribute:
<input type="text" value="11" class="producto form-control" required="required" name="project_backendbundle_pedido[pedidoSubitems][0][number]" id="project_backendbundle_pedido_pedidoSubitems_0_number">
推荐答案
type
属性是通过您选择的小部件类型设置的.要获得 type="number"
,您需要选择 integer
作为小部件类型.令人困惑,我知道..
The type
attribute is set via the widget type you choose. To get a type="number"
you need to choose integer
as widget type. Confusing, I know..
但请查看 官方 symfony 页面.所以你的代码应该是这样的:
But have a look at the official symfony page. So your code should look like this:
->add('number', 'integer', array(
'label' => false,
'attr' => array('class' => 'producto'),
))
这篇关于symfony2:试图添加一个类型=“数字"属性到表单域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文