How to Embed a set of Forms

How to Embed a set of Forms

Symfony Variations is implant a couple of many other forms, that’s useful to edit related organizations in one single setting. In this article, you can easily manage a questionnaire to change a task category and you may, right from inside the same mode, you’ll revise, would and take away many Tag objects about one to Task.

Tips Implant some Versions

Next, let us do a questionnaire for the job organization, having fun with good CollectionType world of TagType models. This may allow us to personalize all Tag components of a role best during the activity means by itself:

If representative submits the shape, the new registered study into the tags profession is employed to build an enthusiastic ArrayCollection regarding Level items. New range will be set on brand new tag field of the new Activity and will getting accessed thru $task->getTags() .

To date, so it works great, however, just to modify current labels. It does not have developed but really to provide the fresh labels otherwise remove established of those.

You could potentially implant nested choices as many account off as you such as. not, by using Xdebug, you may discover an optimum mode nesting amount of ‘100’ hit, aborting! mistake. To resolve so it, boost the xdebug.max_nesting_peak PHP function, or promote per means occupation yourself having fun with form_row() in the place of helping to make the entire function simultaneously (e.g function_widget(form) ).

Allowing “new” Tags towards “Prototype”

In the past your extra several labels for the activity throughout the control. Now allow the profiles put as much mark models because they you prefer in direct this new internet browser. This involves a bit of JavaScript password.

However, first, you ought to let the means collection remember that as opposed to exactly a few, it will located a telephone number out-of labels. Otherwise, you will see a good “This form ought not to have more areas” mistake. This is accomplished into the allow_include option:

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 try a questionnaire ability that appears and you will feels identical to the person form_widget(mark.*) factors within your to have circle. Because of this you could potentially label setting_widget() , form_row() or form_label() inside it. You could potentially actually love to provide only 1 of their sphere (age.grams. title industry):

For people who provide the entire “tags” sub-form at once (elizabeth.g. mode_row(mode.tags) ), the content-model attribute is automatically set in the new that contains div , and you should to evolve another 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

The brand new addFormToCollection() function’s job will be to use the analysis-model characteristic in order to dynamically include a different sort of means if this link try visited. The data-model HTML contains the tag’s text message enter in function with a name out of activity[tags][__name__][name] and you can id away from task_tags___term___label . This new __name__ is an excellent placeholder, which you’ll replace with a new, incrementing matter (elizabeth.grams. task[tags][name] ):

Now, when a person https://datingranking.net/pl/xcheaters-recenzja ticks the fresh Incorporate a label hook up, a unique sandwich means will look towards web page. In the event the means are recorded, any the tag forms would-be turned into the Level things and set in the new tags property of one’s Activity target.

And come up with handling this type of the brand new tags smoother, create an “adder” and you will an excellent “remover” opportinity for the brand new labels on the Task group:

With this several changes, in the event that means try submitted, for every single the latest Mark target was put in the job class of the getting in touch with this new addTag() strategy. Until then changes, they certainly were additional around by the means from the calling $task->getTags()->add($tag) . That was okay, but pressuring using the newest “adder” means produces dealing with such brand new Mark items easier (particularly if you are having fun with Philosophy, that you will learn on the 2nd!).

Comments are closed.