Reputation: 8017
I have a form that contains a collection field-type.
However I don't know how to add/remove fields to/from the collection.
$builder
// ...
->add('covers', 'collection', array(
'required' => false,
'type' => new BookCoverType(),
'allow_add' => true,
))
;
The rendered form looks like this:
How can I add a new cover using the collection form field?
Upvotes: 2
Views: 2671
Reputation: 52503
Symfony does not provide the add/remove JavaScript methods/buttonss or any session-based solution without JavaScript out of the box.
It renders a data-prototype
attribute that can be used as described in the documentation chapter How to Embed a Collection of Forms -> Allowing "new" tags with the "prototype".
Some bundles provide this functionality though. Those are primarily the bootstrap bundles:
Just dive into their code - i.e. braincrafted/bootstrapbundle's bc-bootstrap-collection.js.
Upvotes: 3