Just how to Embed a collection of Forms

Just how to Embed a collection of Forms

Symfony Models is embed a set of a great many other variations, that is good for edit associated organizations in a single setting. In this article, you’ll be able to manage an application so you’re able to change a job category and, proper inside the exact same form, it is possible to revise, create and take off of many Tag objects about you to Task.

Tips Embed a set of Forms

Second, let’s carry out a form for the job entity, having fun with a good CollectionType field of TagType forms. This may allow us to modify the Tag parts of a job correct inside activity form alone:

In the event that member submits the proper execution, the newest filed analysis toward labels profession is used to create a keen ArrayCollection from Level stuff. The fresh new collection will be seriously interested in the fresh new level field of the latest Activity and can getting reached via $task->getTags() .

Thus far, that it is effective, however, only to change present labels. It will not are suffering from but really to add the fresh tags otherwise delete existing ones.

You could implant nested collections as many account down because you including. However, if you use Xdebug, you can discover a max setting nesting quantity of ‘100’ attained, aborting! error. To fix so it, improve xdebug.max_nesting_peak PHP form, or render for every single function occupation by hand playing with form_row() rather than leaving the entire mode at a time (age.grams mode_widget(form) ).

Making it possible for “new” Labels towards the “Prototype”

Previously your additional a couple tags on the task on the control. Today allow pages create as many tag versions while they you would like directly in the fresh new internet browser. This requires a touch of JavaScript code.

However, first, you will want to allow mode range be aware that in the place of precisely one or two, it can discovered a phone number away from tags. If you don’t, you will observe a good “This form cannot have extra industries” mistake. This is done toward create_incorporate option:

The allow_add option also makes a prototype variable available to you. This “prototype” is a little “template” that contains all the HTML needed to dynamically create any new “tag” forms with JavaScript. To render the prototype, add the following data-prototype attribute to the existing

    in your template:

    The proper execution.tags.vars.prototype is an application element that looks and you may seems same as the individual means_widget(level.*) elements in your for cycle. As a result you could potentially telephone call means_widget() , form_row() otherwise means_label() with it menchats nedir. You can actually choose give only 1 of the sphere (age.g. title job):

    For people who promote the “tags” sub-form at the same time (e.g. means_row(mode.tags) ), the content-model trait is actually instantly placed into the fresh that features div , and you ought to to change the next JavaScript correctly.

    Now add some JavaScript to read this attribute and dynamically add new tag forms when the user clicks the “Add a tag” link. Add a