Ok,thank you very much for your answer @Tautrimas Pajaskas, The solution is as follows:
<script type="text/javascript">
$('div[id$=_empDomicilios]').on('sonata.add_element', function(event) {
alert('trigger is fired ');
// insert here your code
});
</script>
API of Jquery says: As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.
If you indeed can send other parameters from the trigger, as follows:
jQuery('#field_container_{{ id }}').trigger('sonata.add_element', ['{{ id }}','{{ sonata_admin.admin.root.id(sonata_admin.admin.root.subject) }}', '{{ sonata_admin.admin.root.uniqid }}']);
Then your javascript code looks like this:
<script type="text/javascript">
$('div[id$=_empDomicilios]').on('sonata.add_element', function(event, elementId, objectId, uniqid) {
alert('trigger is fired '):
alert('ElementId: '+ elementId);
alert('ObjectId: '+ objectId);
alert('Uniqid: '+ uniqid);
// insert here your code
});
</script>
Note: I have used for the example a div with a id attribute value ending with "_empDomicilios".