1

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 ?

PapsOu
  • 135
  • 2
  • 9

1 Answers1

1

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.

Mawcel
  • 1,967
  • 15
  • 22
  • Thanks. The type option « modifiable » solve my problem, the collection is not reset at preSubmit time. – PapsOu Jun 14 '17 at 08:57