从 Symfony DateType::class 禁用日期和月份 [英] Disable days and month from Symfony DateType::class
本文介绍了从 Symfony DateType::class 禁用日期和月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
->add('attendFrom', DateType::class, array('小部件' =>'选择','html5' =>错误的,'月' =>大批(),'天' =>大批(),'属性' =>大批('占位符' =>'开始年份,例如 1980 ',)))
我尝试禁用日期和月份的类型.我只想展示几年.这可能吗?
我找到了一些解决方案来隐藏树枝上的天数和月数,但我想知道是否可以从 FormType 中禁用它.
干杯
解决方案
Put yyyy
in format
option
表格:
->add('attendFrom', DateType::class, array('格式' =>'yyyy','小部件' =>'选择','html5' =>错误的,'属性' =>大批('占位符' =>'开始年份,例如 1980 ',)))
<块引用>
更新 1
在树枝中隐藏月份和日期控件
树枝:
<代码>{{form_widget(form.formName.attendFrom.day,{'属性':{'样式':'显示:无'}})form_widget(form.formName.attendFrom.month,{'属性':{'样式':'显示:无'}})}}
参考:链接
->add('attendFrom', DateType::class, array(
'widget' => 'choice',
'html5' => false,
'months' => array(),
'days' => array(),
'attr' => array(
'placeholder' => 'Start year, e.g., 1980 ',
)
))
There is type from which I try to disable days and month. I want to show only years. Is this is possible?
I had find some solution to hide days and months from a twig but I wonder if I can disable this from FormType.
Cheers
解决方案
Put yyyy
in format
option
Form:
->add('attendFrom', DateType::class, array(
'format' => 'yyyy',
'widget' => 'choice',
'html5' => false,
'attr' => array(
'placeholder' => 'Start year, e.g., 1980 ',
)
))
Update-1
Hide month and day control in twig
TWIG:
{{
form_widget(
form.formName.attendFrom.day,
{
'attr': { 'style': 'display:none' }
}
)
form_widget(
form.formName.attendFrom.month,
{
'attr': { 'style': 'display:none' }
}
)
}}
Ref: Link
这篇关于从 Symfony DateType::class 禁用日期和月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文