Handle external library events inside Template


#1

I am trying to handle external library (Kloudless) events inside my app template yet I am not sure what is the best way to add the library events to my app template. So far using the code below, I am always getting error:

 Uncaught TypeError: Cannot read property 'on' of null

Any thought what I might be doing wrong / missing here? Thanks for your time.

 var explorer = null;

 Template.formA.rendered = function(){
    explorer = window.Kloudless.explorer({
	    app_id: "API_KEY",
	    multiselect: true,
	    computer: true,
	   persist: "local",
	    services: ['all'],
	    display_backdrop: true,
	    create_folder: true,		    
   });
 };

 Template.formA.helpers({
     explorer.choose();
 });

//Events
explorer.on('success', function(files) {
     console.log('Successfully uploaded files: ', files);
});
explorer.on('cancel', function() {
  console.log('File selection cancelled.');
});

#2

try registering your events within the template’s render function, not that im sure thats the best route


#3

If I want register events, I would start
Template.formA.events …


#4

thx a lot for your prompt reply, do you mind providing me with a small example on how to register the event under the template render function? thanks


#5

thx for your help but the event I am addressing here doesn’t match any of Template.events types, for example I am trying to register on.success event or on.finishFileUpload event, which I can’t figure out how to register those events under the Template.events…make sense? thx again


#6

well, your explorer var is null apparently, so why not try to register the events within the template render function after you assign a valid thing to explorer? i know this is different from ensuring that the events you are registering callbacks for are observed by the template…which sounds equally as important :wink:


#7

thx, adding them under template render solved it


#8

glad to hear it works out :slight_smile: