sf_tristanb
sf_tristanb

Reputation: 8855

How to populate manually from db a form select (multivalued)

In my form i have a simple

<select multiple="multiple" name="action[files][]" id="action_files"></select>

outputed by :

  $builder->add('files', 'choice', array('multiple' => true, 'required' => false));

the setFiles() is working, but when displaying an existent record, the getFiles() does not work.

Here's the getter :

public function getFiles()
{
    $array = array();
    $documents = $this->getDocuments();

    foreach ($documents as $document) {
        $array[$document->getFilename()] = $document->getFilename();
    }
    return $array;
}

It'll output :

array(1) { ["slide1.jpg"]=> string(10) "slide1.jpg" } 

But the select is empty.

How can i achieve that please ?

Upvotes: 0

Views: 312

Answers (1)

Bernhard Schussek
Bernhard Schussek

Reputation: 4841

You did not pass the "choices" option to the choice field.

Upvotes: 1

Related Questions