Symfony Models can also be embed a collection of a great many other forms, that is good for modify related organizations in a single means. In this post, it is possible to manage a type so you can edit a task group and you may, best for the same mode, you can edit, create and take off of a lot Level items related to you to definitely Task.
Just how to Embed some Variations
2nd, let’s perform a questionnaire for the job organization, having fun with a CollectionType arena of TagType forms. This will allow us to modify all of the Mark areas of a job best into the task form by itself:
https://datingranking.net/pl/wapa-recenzja/
In the event that representative submits the shape, this new registered data to the labels job can be used to construct an ArrayCollection from Level items. The fresh new range will be set on the latest tag field of the latest Activity and will be utilized thru $task->getTags() .
Thus far, this works great, but only to edit existing labels. It does not allow us yet , to include the fresh new labels otherwise erase established of those.
You might embed nested stuff as numerous accounts off because you such as. not, if you use Xdebug, it’s also possible to discover a max setting nesting quantity of ‘100’ reached, aborting! mistake. To fix it, improve the xdebug.max_nesting_level PHP mode, otherwise bring for each and every mode career by hand playing with means_row() as opposed to helping to make the entire function immediately (age.g function_widget(form) ).
Allowing “new” Tags towards “Prototype”
Prior to now you added one or two labels on activity regarding the control. Today allow profiles incorporate as many level forms as they you desire in direct this new internet browser. This calls for a touch of JavaScript password.
But first, you need to let the function collection remember that instead of exactly a couple of, it does located a telephone number out of labels. Or even, you will see a beneficial “This type should not incorporate most sphere” error. This is done towards the create_put alternative:
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.labels.vars.model is actually a form ability that appears and you may feels same as the person setting_widget(mark.*) factors within your having cycle. Thus you could telephone call means_widget() , form_row() otherwise means_label() inside it. You might also will provide only one of the sphere (e.grams. the name career):
For people who provide the “tags” sub-function at once (age.grams. means_row(form.tags) ), the knowledge-model characteristic was automatically put in this new that features div , and you need to to evolve another 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
Leave a Reply