I am running Symfony 1.2 and utilizing the object helper to create some inline editable fields outside of a form. Because there is no symfony or scriptalicious short cut to create an inline edit tag for multiple choice select boxes (much like input_in_place_editor_tag or Ajax.InPlaceCollectionEditor), I am using object_select_tag with the multiple option set to true to create a select box like so:
<?php
echo object_select_tag($user->getsfGuardPermissions(), 'getId', array (
'include_blank' => false,
'related_class' => 'sfGuardPermission',
'peer_method' => 'doSelect',
'text_method' => '__toString',
'control_name' => 'user_customer_permissions_'.$user_customer->getId(),
'multiple' => true
));
?>
I will then call observe_field to update the object via Ajax when the form is changed. However
The problem is that while $user->getsfGuardPermissions() returns an array of sfGuardPermission objects. They are not selected by default.
After some testing, I found that if you pass it only one sfGuardPermission object instead of an array, the proper option is selected. Is this a limitation of Symfony or is there a different way of doing this? It's hard to believe that symfony would include the 'multiple' option if they didn't allow you to select multiple options by default.
Looking at ObjectHelper.php it is apparent that the function is not expecting an array. How do I select multiple objects by default?