grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Question: How to trigger something (function) on adding asset?

Open theSC0RP opened this issue 6 years ago • 2 comments

Hi, @artf. What is the correct way to trigger a function when an asset is added to the assets by providing the link and then pressing the 'Add Image' button? I am running the open-assets command on an onclick event of a button in a custom panel and then trying to call a function when an image is added to the assets. I am using the following code to trigger a function on adding an image:

editor.on('asset:add', () => {
    // my code
})

The // my code part is running multiple times. (As many times as I open the asset dialog using the button mentioned before) What am I possibly doing wrong?

theSC0RP avatar Nov 03 '20 12:11 theSC0RP

Sorry @theSC0RP but I really don't understand what is your issue here. Are you able to provide a live example and clarify the steps?

artf avatar Nov 08 '20 23:11 artf

Hey, @artf. I fixed the issue by changing the structure of my code. I was doing something wrong (my guess is that multiple instances of asset manager were open which ran the // my code part multiple times)

theSC0RP avatar Nov 09 '20 11:11 theSC0RP