Symfony: How to change a form field attribute in an action?

不想你离开。 提交于 2019-12-07 20:38:48

问题


I've got a functioning form with a sfWidgetFormChoice that acts as a list of checkboxes. I'm able to set the checkboxes to "ticked" by default with the following:

'status' => new sfWidgetFormChoice(array('choices' => array(1, 2, 3), 'multiple' => true, 'expanded' => true), array('checked' => 'checked'))

... where the checkboxes are called "status" and the possible values are 1/2/3.

However, because of something else, instead of ticking them all by default I'd like to be able to control the "checked" status from an action. How do I do this? I've tried everything logical I can think of but I just can't figure out the right syntax.

Basically, I'm looking for something like:

$this->form->getWidget('status')->setAttribute('checked', 'checked');

Anyone?

Thanks.


回答1:


Your syntax seems valid according to the sfForm and sfWidget API documentation.



来源:https://stackoverflow.com/questions/2254620/symfony-how-to-change-a-form-field-attribute-in-an-action

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