Symfony2复选框选择字段:禁用一个复选框 [英] Symfony2 checkbox choice field: disable one checkbox
本文介绍了Symfony2复选框选择字段:禁用一个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一项任务是禁用表单选择字段中的某些复选框,有些不是。有没有一种简单的方法来实现,而不重写选择字段布局?
I have a task to make some of the checkboxes in a form choice field disabled, and some not. Is there an easy way to achieve that without rewriting choice field layouts?
推荐答案
您可以在您的选择字段设置禁用状态:
You can set on your choice field the disabled state :
$builder->add('myChoice', 'choice', array('attr'=>array('disabled'=>'disabled')));
如果您有一些需要设置禁用的逻辑,您可以使用EventSubscriber来侦听PostSetData事件州。
查看食谱动态表单生成以了解实施细节。
Or you could use an EventSubscriber to listen on PostSetData event if you have some logic needed to set the disabled state. Check cookbook dynamic form generation for implementation details.
这篇关于Symfony2复选框选择字段:禁用一个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文