Search code examples
symfony1

How to set selected values using sfWidgetFormSelectMany in Symfony1?


I want to use the sfWidgetFormSelectMany inside a sfForm. I have no problems setting the choices for the select, but how do I set the selected values when loading the form?

This is my code for the sfWidgetFormSelectMany so far:

$choices = $this->getScopes();

$this->widgetSchema['application_scopes'] = new sfWidgetFormSelectMany(array(
  'choices' => $choices
));
$this->validatorSchema['application_scopes'] = new sfValidatorChoiceMany(array(
  'choices' => array_keys($choices)
));

Solution

  • So, I have to answer the question by myself. Sometimes the best way is to ask a question to find the answer ;-)

    As I am inside my form class, I just can set the values like this:

    $this->setDefault('application_scopes', array('this','that'));