开发者

Specific checkboxes checked in symfony 1.4

开发者 https://www.devze.com 2022-12-24 09:44 出处:网络
I\'m able to do the following for all checkboxes in a set (in an action): $this->form->getWidget(\'some_form_field\')->setAttribute(\'checked\', \'checked\');

I'm able to do the following for all checkboxes in a set (in an action):

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

... but I'm unable to set specific checkboxes to ticked on the basis of data returned from the db.

I'm after something like:

$this->form->getWidget('some_form_field')->setAttributes(array(....));

... where I can refer to the specific checkboxes to be ticked somehow, or pass an array to it.

There's n开发者_JAVA百科othing in the symfony documentation on this specifically and I've had enough of trying a dozen combinations to get it work.

Any help would be appreciated.

Thanks.


This sounds a bit unusual? Are you using the generated propel/doctrine forms? They should handle it automatically.

Either way, setting the checked attribute is not the correct way to achieve this. Better way is within the form (because as far as I remember, $this->widgetSchema is protected) to do:

$this->widgetSchema['some_form_field']->setDefault(array('value1', 'value2'));

That will then cause widgets with those values to be checked.

(if thats not right, I wrote it off the top of my head, I can dig some code out and check, so let me know!)

0

精彩评论

暂无评论...
验证码 换一张
取 消