Sonata Admin Forms with dynamic fields

1,372 views
Skip to first unread message

Edgar ochieng'

unread,
Jul 22, 2014, 2:23:18 AM7/22/14
to sonata...@googlegroups.com

My EntryAdmin form needs three or four extra fields for different Campaigns defined by users and handled via entity CampaignProperties then appended via ajax dynamically when corresponding radio button is checked.

I have an EntryProperty table which then should store entry_id, property_id and value.

My intention was to save the extra fields on Entry entity's postPersist event.

I have extended the edit.html.twig which appends fields on the form fine but now I'm stuck when it comes to persisting as extra fields throw the error 'This form should not contain extra fields.'.

Anyone with a idea how to solve this?

Cassiano Tartari

unread,
Jul 22, 2014, 7:22:54 AM7/22/14
to sonata-users
Have you read this: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html?

You can create a form type with your dependent fields add an 'field' in your configureFormFields. Note that this 'field' could be just a get and set of your entity. For example, I've created a region > city field and in my entity I have setRegionCity and getRegionCity, in configureFormFields: ->add('regionCity', 'region', array('label' => false))



Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.

Andrés Llerena

unread,
Dec 2, 2014, 2:56:43 AM12/2/14
to sonata...@googlegroups.com
Hi Cassiano. I have tried to follow the symfony tutorial but i get different error messages. If you have a example, could you please share it here?

Regards,
Andrés
Reply all
Reply to author
Forward
0 new messages