PapsOu
PapsOu

Reputation: 135

sonata_type_collection is cleared on preSubmit

Related to this issue : https://github.com/sonata-project/SonataCoreBundle/issues/408, I have an unexpected behavior of a custom sonata_type_collection.

The collection is used as an EAV model to build dynamic forms througth a standard sonata_type_collection.

When submitting the form with an error (e.g. a mandatory field that is empty) the re-rendered form loose it's structure. The collection is built in a PRE_SET_DATA form events, but when submitting, the preSubmit event « destroy » the collection built in PRE_SET_DATA.

My question, is there a way to avoid the collection clearing at submit time ?

Upvotes: 1

Views: 133

Answers (1)

Mawcel
Mawcel

Reputation: 2007

The ResizeFormListener attached to your form field is probably causing this behaviour as it removes empty rows from the collection when you submit the form.

You should add the modifiable => false option when adding your collection field to the FormMapper.

With this option the ResizeFormListener will not be attached thus empty collection elements won't be removed on submit.

Upvotes: 1

Related Questions