AmoLatina visitors

Tips Implant a couple of Forms

Tips Implant a couple of Forms

Symfony Forms can be implant some a number of other models, that is beneficial to change associated organizations in one form. In this post, you’ll be able to carry out an application so you’re able to revise a task class and you will, right within the exact same mode, you are able to modify, manage and take off many Mark objects connected with you to definitely Activity.

How-to Implant a set of Versions

Second, why don’t we create an application to do the job organization, using an excellent CollectionType realm of TagType models. This can allow us to tailor most of the Tag parts of a job proper for the activity setting itself:

When the affiliate submits the proper execution, the latest submitted research toward tags field can be used to create an ArrayCollection off Tag objects. Brand new range is then seriously interested in brand new mark arena of the brand new Activity and will end up being accessed via $task->getTags() .

At this point, it works great, however, only to modify existing labels. It will not have developed yet to incorporate the latest tags or delete established of them.

You could implant nested selections as much account off since you particularly. not, by using Xdebug, you’ll be able to discover a max means nesting quantity of ‘100’ hit, aborting! error. To resolve so it, help the xdebug.max_nesting_height PHP function, or render for each and every setting field yourself having fun with form_row() instead of helping to make the whole mode immediately (elizabeth.grams function_widget(form) ).

Enabling “new” Labels into the “Prototype”

In the past you added a couple tags toward activity on operator. Now allow the users create as many level forms while they you want directly in this new browser. This requires a little bit of JavaScript code.

However, earliest, you need to allow the setting range know that unlike just two, it does found a phone number from tags. Otherwise, you will notice a beneficial “This type ought not to include extra sphere” error. This is accomplished toward create_add 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 form.tags.vars.model was a questionnaire element that appears and you will seems same as anyone function_widget(mark.*) facets within your getting circle. Because of this you might call means_widget() , form_row() or mode_label() involved. You might also desire render one of the industries (age.grams. the name industry):

    For folks who give the whole “tags” sub-function at a time (elizabeth.g. setting_row(means.tags) ), the details-prototype trait was instantly put into brand new which includes div , and you should to change the following 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