Matt
Matt

Reputation: 2843

Symfony dynamic form fields in event subscriber

Following the example as documented in the following http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html

This adds the fields in the event subscriber first, then adds the fields that have been added in the form type.

Does anybody know how to change the ordering around so that the form type fields appear first in the form view, then the fields added in the event subscriber appear after?

Thanks in advance

Upvotes: 0

Views: 679

Answers (2)

Paweł Suwiński
Paweł Suwiński

Reputation: 11

I had the same problem. I solved it by moving form building ($builder->add(...)) from MyFormType::buildForm() to listener leaving there only $builder->addEventSubscriber(...) statement.

Upvotes: 1

Ahmed Siouani
Ahmed Siouani

Reputation: 13891

There's two different manner to order your fields,

  • When building your form, you've to add fields according to the order you went to display them, it allows you to get the right behavior using form_widget(form).

  • Customize your form rendering. You can then put every part of your form in the right position so that it looks the way you want.

Upvotes: 0

Related Questions