How exactly to Embed a set of Forms

How exactly to Embed a set of Forms

Symfony Forms is implant some many other models, that is useful to change related entities in one single means. In this post, you can easily perform a questionnaire to help you modify a job category and, proper in same means, you are able to revise, do and remove many Level items pertaining to one to Task.

Ideas on how to Embed some Forms

Next, let’s manage an application for the task entity, playing with good CollectionType world of TagType forms. This can help us modify most of the Tag elements of a task right inside task form by itself:

When the representative submits the shape, the fresh new submitted investigation into tags job is utilized to build an ArrayCollection off Level items. The newest range will then be set on the latest level realm of the new Task and will getting reached thru $task->getTags() .

At this point, it is effective, but merely to edit current tags. It generally does not allow us yet , to provide brand new labels otherwise erase existing ones.

You could embed nested selections as much account off since you such as. However, if you use Xdebug, it is possible to discovered a maximum form nesting quantity of ‘100’ attained, aborting! error. To fix which, increase the xdebug.max_nesting_level PHP setting, or render for each and every setting community yourself having fun with means_row() in place of leaving the whole setting at the same time (age.g setting_widget(form) ).

Enabling “new” Tags toward “Prototype”

In earlier times your additional a couple of tags on the task on the controller. Now let the pages incorporate as numerous tag versions as they you want directly in the newest internet browser. This involves just a bit of JavaScript password.

But very first, you will want to let the form range be aware that unlike precisely a couple of, it does located a telephone number of tags. Or even, you will see an effective “This type ought not to have most areas” mistake. This is done toward allow it to be_include 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 form.labels.vars.prototype are a form ability that appears and you may seems same as the individual setting_widget(tag.*) elements within your to own cycle. Because of this you could potentially telephone call function_widget() , form_row() or mode_label() on it. You can also desire bring only 1 of its industries (e.grams. title career):

    For people who bring the whole “tags” sub-function at the same time (e.grams. function_row(setting.tags) ), the information-prototype attribute are automatically put into the fresh which has div , and you ought to to switch 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