Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have always used form_widget to render embedded forms, but I think form_row will work fine too. The important thing you should look at is if the embedded form container has a "data-prototype" attribute. Then, you must add a script to the page where you are displaying the form. In my case, I use Mootools, but I gues you can easily translate this script to jQuery or any other javascript framework:</p> <p>These are the contents of my js file (you should replace "XXX" for the id of the element where the "data-prototype" attribute is:</p> <pre><code>window.addEvent( 'domready', function() { var add = function() { var collectionHolder = $('XXX'); var prototype = collectionHolder.getAttribute('data-prototype'); form = prototype.replace(/\$\$name\$\$/g, collectionHolder.getChildren().length); var cont = Elements.from(form); collectionHolder.adopt( cont ); } var remove = function() { var collectionHolder = $('XXX'); var child = collectionHolder.getLast(); child.dispose(); } $$('a.add-link').addEvent('click', function(e){ e.stop(); add(); }); $$('a.remove-link').addEvent('click', function(e){ e.stop(); remove(); }); </code></pre> <p>});</p> <p>This script is very simple, and just adds new elements or removes the last element in the collection. Besides, you should add some html to your view in order to have add/remove links:</p> <pre><code>&lt;ul class="actions"&gt; &lt;li&gt; &lt;a href="#" class="add-link"&gt; Add &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#" class="remove-link"&gt; Remove last &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I hope it helps, I'm new to Symfony and I'm still learning, but it worked for me :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload