Symfony Versions normally embed some a number of other variations, that is beneficial to edit related agencies in one function. On this page, you’ll be able to perform a form so you can edit a role class and, correct in same setting, it is possible to revise, create and remove of numerous Level things related to you to definitely Activity.

How-to Embed a couple of Forms

Next, let’s do a type for the job entity, having fun with a CollectionType arena of TagType models. This may help us modify all the Level parts of a job best within the task means alone:

If user submits the proper execution, brand new recorded investigation for the tags occupation can be used to construct an enthusiastic ArrayCollection away from Mark stuff. The fresh new range will then be seriously interested in brand new tag realm of the Task and will getting accessed via $task->getTags() .

Up to now, that it works great, but only to edit present tags. It does not have developed yet to add the fresh new tags otherwise remove established of them.

You could potentially implant nested selections as many accounts off as you eg. Although not, if you are using Xdebug, you can also discovered an optimum mode nesting quantity of ’100′ attained, aborting! error. To solve so it, improve xdebug.max_nesting_top PHP function, otherwise provide for each and every function career yourself having fun with mode_row() in the place of helping to make the entire means simultaneously (age.grams setting_widget(form) ).

Making it possible for « new » Labels for the « Prototype »

In earlier times your added two tags into the activity on the control. Today let the profiles incorporate as much tag models while they you prefer in direct the internet browser. This involves a little bit of JavaScript password.

But earliest, you really need to let the function collection be aware that instead of precisely a couple of, it can receive a telephone number away from labels. If you don’t, you will see an effective « This form should not include most fields » error. This is accomplished into allow it to be_put 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.tags.vars.prototype try a questionnaire function that appears and you may feels identical to the individual means_widget(level.*) points in your to own loop. Consequently you can label function_widget() , form_row() otherwise means_label() inside it. You could also will offer just one of their areas (age.g. title career):

    If you offer your whole « tags » sub-form at once (e.g. means_row(means.tags) ), the details-prototype trait is actually immediately placed into the fresh new which includes div , and you need to adjust next 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 tag somewhere on your page to include the required functionality with JavaScript:

    The latest addFormToCollection() function’s work is to utilize the study-prototype attribute to help you dynamically create a unique form if this link is clicked. The information-model HTML gets the tag’s text input element having a reputation out-of activity[tags][__name__][name] and id off task_tags___name___term . The brand new __name__ is actually a beneficial placeholder, which you can replace a new, incrementing matter (age.grams. task[tags][name] ):

    Today, whenever a user presses the new Put a tag hook, a special sub function can look into the web page. If form are registered, any new tag models might possibly be turned into the Tag items and you will added to the fresh new tags property of your own Task target.

    And come up with dealing with such this new tags much easier, put an « adder » and you can an effective « remover » opportinity for new labels from the Activity category:

    With these two change, if the means was filed, each the latest Mark object are put into the work group of the calling the latest addTag() means. Until then alter, they certainly were added inside of the means by the getting in touch with $task->getTags()->add($tag) . Which was great, but forcing the usage the fresh « adder » method can make handling these types of the new Level objects simpler (especially if you are having fun with Doctrine, which you https://www.datingranking.net/cs/flirthookup-recenze will discover about next!).

Leave a Comment

STYLE SWITCHER

Layout Style

Header Style

Accent Color