Is it possible to catch the trigger that opened the dashboard?


#1

Starting from issue 326 and the subsequent pull 328, I’m wondering if there’s a way to get inside Uppy which was the button (DOM element I mean) that triggered the opening of the dashboard. This can be useful for me to slightly change the upload behavior depending on the upload intension of the user (and so the different buttons).
The only idea that I come up with is not a pretty one: to listen on the click of the buttons and then set a global variable that can be read inside uppy.

Thank you!


#2

can I get inside uppy which was the button that triggered its opening?

Hi! This seems a little like an edge-case to me, but I guess an event could be added, like dashboard:open and we’d pass a trigger element in a callback:

uppy.on('dashboard:open', (trigger) => {
  if (trigger.classList.contains('button-1')) doX()
})

However I’m wondering how would you then change the upload behavior? My example is “outside Uppy”.

It may be easier to just use the newly exposed methods on the Dashboard https://uppy.io/docs/dashboard/#Methods, and make your own triggers? But perhaps you are talking about something different, and then we might need some clarifications, please?


#3

@artur in the end we’ve made a custom event listener to catch the element that triggered the opening. This is useful for us because we have multiple uploaders in a single page, depending on the typology, and each upload will be treated differently on the backend.


#4

Cool! But then if you are using multiple Uppy instances per page, you could also pass some specific metadata with each upload, that would tell the server which one was used:

var uppy = Uppy({
  meta: {
    uploader: 'theMainPageOne'
  }
})

...

var anotherUppy = Uppy({
  meta: {
    uploader: 'theOtherOne'
  }
})

#5

You’re right, but I don’t like very much the code repetition and having multiple instances of Uppy running at the same time. But maybe in the future we’ll go down this road to better separate the various uploaders. Thanks for the help!