Ver código fonte

Merge pull request #1790 from EmmanuelVella/patch-11

Trigger sonata-admin-append-form-element event on collection form type
Thomas 11 anos atrás
pai
commit
25b7d5dbc5
2 arquivos alterados com 18 adições e 3 exclusões
  1. 14 2
      Resources/doc/reference/form_types.rst
  2. 4 1
      Resources/public/base.js

+ 14 - 2
Resources/doc/reference/form_types.rst

@@ -222,9 +222,21 @@ btn_add and btn_catalogue:
   corresponding button. You can also specify a custom translation catalogue
   for this label, which defaults to ``SonataAdminBundle``.
 
+**TIP**: A jQuery event is fired after a row has been added (``sonata-admin-append-form-element``).
+You can listen to this event to trigger custom javascript (eg: add a calendar widget to a newly added date field)
+
+collection
+^^^^^^^^^^
+
+This bundle handle the symfony ``collection`` form type by adding:
+* an ``add`` button if you set the ``allow_add`` option to ``true``.
+* a ``delete`` button if you set the ``allow_delete`` option to ``true``.
+
+**TIP**: A jQuery event is fired after a row has been added (``sonata-admin-append-form-element``).
+You can listen to this event to trigger custom javascript (eg: add a calendar widget to a newly added date field)
+
 **TIP**: A jQuery event is fired after a row has been added (``sonata-collection-item-added``)
-or deleted (``sonata-collection-item-deleted``). You can bind to these events to trigger custom
-javascript imported into your templates (eg: add a calendar widget to a newly added date field)
+or deleted (``sonata-collection-item-deleted``). You can listen to these events to trigger custom javascript.
 
 FieldDescription options
 ^^^^^^^^^^^^^^^^^^^^^^^^

+ 4 - 1
Resources/public/base.js

@@ -191,7 +191,10 @@ var Admin = {
             var parts = container.attr('id').split('_');
             var nameRegexp = new RegExp(parts[parts.length-1]+'\\]\\['+protoName,'g');
             proto = proto.replace(nameRegexp, parts[parts.length-1]+']['+(container.children().length - 1));
-            jQuery(proto).insertBefore(jQuery(this).parent());
+            jQuery(proto)
+                .insertBefore(jQuery(this).parent())
+                .trigger('sonata-admin-append-form-element')
+            ;
 
             jQuery(this).trigger('sonata-collection-item-added');
         });