Categories
AdultSpace visitors

Just how to Implant a set of Forms

Just how to Implant a set of Forms

Symfony Forms can be embed a couple of many other forms, that is good for revise relevant entities in one setting. In this article, you are able to would an application to revise a job group and you can, correct from inside the same setting, you can easily edit, carry out and remove many Tag things associated with you to Task.

Ideas on how to Implant a collection of Models

2nd, why don’t we do an application for the job organization, having fun with a great CollectionType realm of TagType versions. This can allow us to customize all Level areas of a job right within the task form by itself:

When the representative submits the design, the latest filed investigation on tags career can be used to build an ArrayCollection out-of Mark objects. New range will be seriously interested in the latest level arena of the fresh new Activity and can feel reached through $task->getTags() .

Up to now, it is effective, however, simply to edit existing labels. It will not are suffering from yet , to add the fresh new tags otherwise delete existing of them.

You could potentially implant nested choices as much profile down as you for example. However, by using Xdebug, you may also discover a maximum mode nesting quantity of ‘100’ reached, aborting! mistake. To solve this, improve the xdebug.max_nesting_top PHP form, or provide for each form field by hand playing with form_row() as opposed to helping to make the entire mode immediately (age.g mode_widget(form) ).

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

In earlier times your added a few tags with the task in the controller. Today let the users add as much mark forms while they you need directly in the web browser. This requires a touch of JavaScript code.

However, first, you really need to allow mode collection remember that in place of exactly a couple of, it will found an unknown number out of labels. If not, you will see an effective “This type should not consist of even more fields” mistake. This is done on the enable it to be_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 form.labels.vars.model try an application function that looks and you may seems same as the person mode_widget(level.*) aspects in your getting cycle. This means that you might name form_widget() , form_row() otherwise form_label() inside it. You might even want to promote one of the industries (age.grams. title job):

    For people who bring the “tags” sub-setting at the same time (age.grams. function_row(form.tags) ), the content-prototype attribute try immediately placed into the fresh that features div , and you ought to to change the following JavaScript consequently.

    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 1