Symfony:如何更改操作中的表单字段属性?
我有一个带有 sfWidgetFormChoice 的功能表单,它充当复选框列表。我可以通过以下方式将复选框默认设置为“勾选”:
'status' => new sfWidgetFormChoice(array('choices' => array(1, 2, 3), 'multiple' => true, 'expanded' => true), array('checked' => 'checked'))
...其中复选框称为“状态”,可能的值为 1/2/3。
然而,由于其他原因,我希望能够通过操作控制“已检查”状态,而不是默认情况下全部勾选。我该怎么做?我已经尝试了我能想到的所有逻辑,但我就是无法找出正确的语法。
基本上,我正在寻找类似的东西:
$this->form->getWidget('status')->setAttribute('checked', 'checked');
有人吗?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 sfForm 和 sfWidget API 文档。
Your syntax seems valid according to the sfForm and sfWidget API documentation.