2

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.

Tom
  • 30,090
  • 27
  • 90
  • 124
  • 1
    Does it not work or what is your problem? Because your syntax seems valid. Any error messages? – Felix Kling Feb 12 '10 at 19:50
  • Uhhh... that's crazy. It DOES work! Well, thanks for making me trying it again, must have been something cached in my browser. – Tom Feb 12 '10 at 19:54
  • If you want to add an "answer" I can mark it as accepted for you. – Tom Feb 12 '10 at 19:55

1 Answers1

3

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

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143