Symfony Models normally embed a set of a number of other versions, which is advantageous to modify associated entities in one single means. In this article, you’ll be able to perform a type so you can edit a task category and, best from inside the same means, you’ll edit, do and take away of several Level objects about you to Activity.
Simple tips to Embed a collection of Variations
Next, let’s do a questionnaire to do the job entity, having fun with an excellent CollectionType realm of TagType variations. This can allow us to personalize most of the Mark components of a role proper within the activity function alone:
In the event that https://datingranking.net/cs/mamba-recenze/ affiliate submits the form, the fresh registered data on tags profession can be used to construct an ArrayCollection out-of Mark stuff. The newest collection will then be intent on the fresh level field of new Task and can end up being reached via $task->getTags() .
Thus far, so it works great, however, just to edit existing tags. It doesn’t have developed yet , to incorporate the fresh new tags or delete current ones.
You might embed nested collections as numerous account off since you eg. However, if you use Xdebug, it’s also possible to receive an optimum function nesting level of ‘100’ hit, aborting! mistake. To resolve it, boost the xdebug.max_nesting_level PHP form, otherwise offer for every single setting profession yourself using form_row() in place of leaving the complete means immediately (elizabeth.g function_widget(form) ).
Allowing “new” Labels towards “Prototype”
In the past you added a few labels to your activity in the operator. Now allow the profiles put as numerous mark variations while they you want directly in the fresh browser. This requires a bit of JavaScript password.
However, earliest, you really need to let the means range remember that as opposed to precisely a few, it can discover an unknown number out of labels. If not, you will observe good “This form ought not to consist of a lot more fields” error. This is done towards the enable it to be_create choice:
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 shape.tags.vars.prototype is actually a questionnaire ability that looks and you will feels same as anyone setting_widget(tag.*) issues within your to have cycle. Because of this you could potentially phone call setting_widget() , form_row() otherwise setting_label() with it. You can actually like to offer only 1 of the industries (elizabeth.g. the name job):
For those who bring your whole “tags” sub-mode at once (elizabeth.grams. setting_row(function.tags) ), the data-model feature was immediately put into the newest containing div , and you need to adjust the next JavaScript properly.
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
