Ideas on how to Embed a collection of Versions
Symfony Forms can be embed a collection of many other forms, that is https://datingranking.net/pl/twoo-recenzja/ advantageous to modify related organizations in one single function. On this page, you’ll be able to carry out an application to edit a role class and, proper during the same form, you’ll be able to edit, perform and remove of several Mark stuff associated with one to Task.
Just how to Implant some Variations
2nd, let’s perform a type for the job organization, having fun with a beneficial CollectionType world of TagType versions. This can allow us to personalize most of the Tag elements of a task best for the task function by itself:
If member submits the proper execution, the newest filed research to the labels profession can be used to build an enthusiastic ArrayCollection off Mark things. This new collection will then be seriously interested in the latest mark field of the fresh Task and certainly will be reached thru $task->getTags() .
Up to now, this works great, however, just to edit present tags. It doesn’t are suffering from yet to incorporate the tags or delete established of those.
You might embed nested collections as many profile down since you such as for example. But not, when you use Xdebug, you are able to found a max means nesting level of ‘100’ achieved, aborting! error. To solve so it, improve xdebug.max_nesting_peak PHP setting, otherwise provide for every function occupation manually using means_row() in lieu of helping to make the complete mode at once (e.grams function_widget(form) ).
Allowing “new” Tags into the “Prototype”
Before you additional two tags towards task on the control. Now let the users add as many tag forms because they you want in direct the fresh new web browser. This requires a little bit of JavaScript code.
But very first, you need to allow function range know that in lieu of exactly two, it does receive a phone number from tags. Otherwise, you’ll see an excellent “This form cannot include extra areas” mistake. This is accomplished into the allow it to be_create 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 design.tags.vars.prototype are a questionnaire ability that appears and you can seems identical to anyone function_widget(mark.*) issues inside your to have loop. Because of this you could telephone call form_widget() , form_row() otherwise mode_label() in it. You could potentially even will bring just one of its industries (elizabeth.grams. title community):
If you promote the “tags” sub-setting at a time (e.grams. mode_row(form.tags) ), the data-prototype trait is instantly placed into the latest that contains div , and you should to improve the following JavaScript accordingly.
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