smkctk
smkctk

Reputation: 1

How to change a setting in jquery plugin after it's been initialized

I have a form that is submitting files via ajax to a restful API. In order to do this I am using Hayageeks jQuery Upload File Plugin.

The script is working fine except for when I need one of the settings (the URL), to be changed after initialization. The route will be different for each file depending upon what menu selections are chosen by the user.

Initialization when document is ready:

$(function(){
    var settings = {
        url: "default_url",
        autoSubmit:false
    }

    uploadObj = $("#mulitplefileuploader").uploadFile(settings);
}); 

Event where I want the url to be set:

$("#btnSubmit").on('click', function() {
    uploadObj.uploadFile(
        url: "new_url"
    );

    uploadObj.startUpload();
});

What do I need to do in order for this to work?

Upvotes: 0

Views: 190

Answers (2)

smkctk
smkctk

Reputation: 1

I found out that the plugin has an update method that accepts new settings at runtime.

uploadObj.update({url:newUrl,maxFileCount:3,showDownload:false});

I was only able to get this to work in an onchange event though, for some reason it wouldn't work with the click event.

Upvotes: 0

Bas Slagter
Bas Slagter

Reputation: 9929

You need to call $("#mulitplefileuploader").uploadFile(settings); again with the new settings.

Upvotes: 1

Related Questions