How exactly to Embed a couple of Forms

Symfony Variations is embed a set of many other variations, that’s advantageous to modify related organizations in a single form. In this post, you’ll do an application in order to modify a role group and you will, best into the same setting, you’ll edit, would and remove many Mark stuff linked to one to Task.

Just how to Embed some Versions

Second, let us carry out a questionnaire to do the job entity, having fun with a CollectionType world of TagType forms. This may allow us to tailor all Tag components of a job correct when you look at the activity means in itself:

If the associate submits the form, the newest filed research into labels community is utilized to build a keen ArrayCollection out-of Tag things. The newest collection will be seriously interested in the brand new level world of the latest Task and can end up being utilized through $task->getTags() .

Thus far, so it works great, however, simply to edit present tags. It will not have developed but really to include new tags or delete current ones.

You could potentially embed nested collections as many account off since you instance. Although not, by using Xdebug, you are able to found an optimum form nesting amount of ‘100’ attained, aborting! mistake. To fix that it, boost the xdebug.max_nesting_level PHP means, or render for every single means occupation yourself having fun with setting_row() in lieu of leaving the whole means at the same time (age.grams means_widget(form) ).

Enabling “new” Labels into the “Prototype”

Prior to now your added one or two tags with the task in the operator. Today allow the profiles put as numerous level models while they you desire in direct brand new browser. This requires a touch of JavaScript password.

However, earliest, you really need to allow function collection remember that in place of precisely a few, it does found an unknown number of tags. Or even, you will observe a “This type cannot contain additional areas” mistake. This is accomplished for the allow_include solution:

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 design.tags.vars.prototype was a form feature that appears and you may seems identical to the person mode_widget(level.*) points within your getting cycle. This means that you can phone call mode_widget() , form_row() or means_label() involved. You could even love to give only one of its fields (age.g. title career):

    For individuals who provide the whole “tags” sub-means immediately (age.grams. mode_row(form.tags) ), the data-model attribute are instantly put into the new containing div , and you should to alter next JavaScript appropriately.

    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