Search code examples
sonata-admin

Loading sonata_type_colletion field via ajax


I'm using sonata admin in my project I have two entities, Order and Delivery which are related in a oneToMany relationship. Each of these has a oneToMany relationship with OrderItem and DeliveryItem respectively.

I would like to make it easier when creating a Delivery by loading corresponding Order Items by pre-populating the items delivered through an ajax call based on Order item selected.

I extended the edit theme and can make the ajax call which populates fine, however when trying to save, I get the error in relation to my form having extra fields even though I've followed sonata admin's naming convention to the letter.

Is there a way to do this?


Solution

  • when calling formMapper->add() you can pass the 'allow_extra_fields' => true option.

    http://symfony.com/doc/current/reference/forms/types/form.html#allow-extra-fields