File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -917,6 +917,31 @@ the following inside ``ProductType``:
917917 )); 
918918 } 
919919
920+ 
921+ the collection form in your view. The prototype is a row of the collection
922+ without any data in it that serves as a template to add more items.
923+ To do so, you must set the ``prototype `` and ``allow_add `` options to ``true ``.
924+ 
925+ When your collection will be rendered, the html element containing your
926+ collection (div or table) will have a ``data-prototype `` attribute containing
927+ the rendered prototype, as a string. In order for you to display the
928+ prototype, you'll have to write a small JS to capture the attribute
929+ and insert it in the form. Here is a sample that you will have to adapt.
930+ 
931+ .. code-block :: javascript 
932+  < script type= " text/javascript" >  
933+  jQuery (' #add-element' click (function () { 
934+  var  prototype =  $ (' form#my_form #my_collection' attr (' data-prototype'  
935+ 
936+  //  the level of the prototype is replaced by $$name$$ 
937+  //  you have to change this to the number of items + 1 
938+  prototype =  prototype .replace (/ \$\$ name\$\$ / g' 00'  
939+ 
940+  //  Append the prototype to the DOM 
941+  $ (' #my_prototype' append (prototype); 
942+  }); 
943+  < / script>  
944+ 
920945index ::
921946 single: Forms; Theming
922947 single: Forms; Customizing fields
                         You can’t perform that action at this time. 
           
                  
0 commit comments