sitecoresitecore8sitecore-speak-ui

Call the trigger method from custom javascript


I am using the uploader control to upload a file. But I want to call a custom javascription after the upload completed. Is there any way i can specify multiple Click actions for a Button?

Or Is there a way to invoke the Trigger methods from custom javascript?

define(["sitecore"], function (Sitecore) {
  var UploadContacts = Sitecore.Definitions.App.extend({
      initialized: function () {
      },
      uploadFile: function () {
          this.FileUploader.upload();
          // custom calls
      }
  });

  return UploadContacts;
});

Solution

  • I have done the same as your looking for here. The way I have done this is to specify a function for the uploader control to call back to on the upload completing.

    In the initialize of your page code do something like this.

    initialize: function () {
      this.on("upload-fileUploaded", this.FileUploaded, this);
    },
    
    1. "upload-fileUploaded" is the event your subscribing too, file uploaded.
    2. "this.FileUploaded" this is the JS function you want to call for each uploaded file.

    Here is an example of my call back function, the modal contains a reference to the uploaded item within Sitecore.You can get the Sitecore item ID of the newly created item as below.

    FileUploaded: function (model) {
    
                this.filesUploaded.push(model.itemId);
    
                this.upFiles.viewModel.refreshNumberFiles();
    
                if (this.upFiles.viewModel.globalPercentage() === 100) {
                    this.ImportData();
                }
            }