Is there any "easy" way to handle collection type on entity creation form?
What I've got:
namespace AppBundle\Entity;
// ...
class Book
{
// ...
/**
* @ORM\Column(type="array", nullable=true)
*/
private $otherTitles;
// ...
}
In the form builder:
// ...
->add('bookOtherTitles', 'collection', array(
'label' => "Other Title(s)",
'required'=>false,
'allow_add'=>true
))
// ...
What I want - in the Perfect World - is that the field would display one text text input (ok, a vars.prototype can do that one) and a little "+" sign next to it, allowing me to add more fields, but probably I will have to do it myself in JS. My question is, is my approach the best one here (with array entity field and collection field in form)?
Bonus question: how to handle multiple inputs - I assume i need to trick the form into giving them names with []?
Maybe I started in a wrong way? I didn't create a separate entity for that field, because I know every "other title" will be just string and will not be assigned to any other Book. Maybe that was a mistake? Should I create an entity with only one field and use OneToMany in Book entity?