Explorar el Código

Merge pull request #744 from omissis/patch-1

Added two custom events to enable additional js to be executed after the...
Thomas hace 13 años
padre
commit
f81ec77fc4
Se han modificado 2 ficheros con 6 adiciones y 0 borrados
  1. 2 0
      Resources/doc/reference/form_types.rst
  2. 4 0
      Resources/public/base.js

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

@@ -21,6 +21,8 @@ sonata_type_collection
 
 The ``Collection Type`` is meant to handle creation and edition of model collections. Rows can be added and deleted, and your model abstraction layer may allow you to edit fields inline.
 
+**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 them to trigger some custom javascript imported into your templates(eg: add a calendar widget to a just added date field)
+
 Type configuration
 ^^^^^^^^^^^^^^^^^^
 

+ 4 - 0
Resources/public/base.js

@@ -157,12 +157,16 @@ var Admin = {
             var proto = container.attr('data-prototype');
             proto = proto.replace(/\$\$name\$\$/g, container.children().length);
             jQuery(proto).insertBefore(jQuery(this).parent());
+            
+            jQuery(this).trigger('sonata-collection-item-added');
         });
 
         jQuery(subject).on('click', '.sonata-collection-delete', function(event) {
             Admin.stopEvent(event);
 
             jQuery(this).closest('.sonata-collection-row').remove();
+            
+            jQuery(this).trigger('sonata-collection-item-deleted');
         });
     }
 }