Friday, 6 September 2013

Symfony2 embedded forms + dynamic form update

Symfony2 embedded forms + dynamic form update

I have a dropdown menu in my form and the form structure depends on its
value. I have managed to solve the "form-update-issue" with event
subscriber/listener class, where i am trying to update the main form
according to dropdown's value.
The main problem is that i have to modify the form from values that
persisted in the database. My DB schema:
I have 4 table: Model, ModelCategory, ModelCategoryKey, ModelParameter.
ModelCategory 1--n Model 1--m ModelParameter
ModelCategory 1--n ModelCategoryKey
ModelCategoryKey 1--n ModelParameter
After the user choose a ModelCategory from the form's (form based on Model
entity) dropdown i have to update the form with ModelParamater rows, but
it's number and default values depends on ModelCategory 1--n
ModelCategoryKey assocaiton.
I've tried to attach NEW ModelParameter entities to the main Model entity
during the PRE_BIND event (also set their default values) and it seems
working fine, but when i add the 'parameters' with a 'collection' typed
element to the form i get the next error:
Entities passed to the choice field must be managed. Maybe persist them in
the entity manager?
Clearly my entities can't be (and shouldn't be) persisted at this time.
All ideas are welcome!

No comments:

Post a Comment