Sanjay
Sanjay

Reputation: 781

Krajee Bootstrap fileinput how can i change the uploadExtraData dynamically

Hi Am using Krajee Bootstrap fileinput , i need to change the uploadExtraData dynamically on submitting the form. So i made it as a call back function. But it doesn't work for me. As i think uploadExtraData callback function work at on initialization only.

here is my code

$(".file-loading").fileinput({
     uploadUrl: document.location.origin + "/discussions/add",
     uploadAsync: false,
     uploadExtraData:getFormData(),
 });

function getFormData(){
    var project_id = $("#DiscussionProjectId").val();
    var discussion_title = $("#DiscussionDiscussionTitle").val();
    var comment = $('#discussionComment').attr('value');
    var data = {
        project_id:project_id,
        discussion_title:discussion_title,
        comment:comment
    };
    return data;
}

Am doing to save the input files and data on form submit only.

Upvotes: 3

Views: 5540

Answers (2)

Andrey Tagaew
Andrey Tagaew

Reputation: 1603

Its also possible to destroy the control and recreate it again

self.jqueryObjects.fileInput.fileinput('destroy');

    self.jqueryObjects.fileInput.fileinput({
        showCaption: false,

        uploadUrl: self.urls.uploadDocument.replace(/<patient_id>/g, self.selectedPatient.id),

        allowedFileExtensions: ["txt"]
    });

Upvotes: 0

user5726736
user5726736

Reputation: 81

I met the same problem with you,you can try this:

$(".file-loading").fileinput({
  uploadUrl: document.location.origin + "/discussions/add",
  uploadAsync: false,
  uploadExtraData:function(previewId, index) {
        var data = {
            project_id : $("#DiscussionProjectId").val(),
            discussion_title:$("#DiscussionDiscussionTitle").val(),
           comment:$('#discussionComment').attr('value')
        };
        return data;
    },
});

Upvotes: 7

Related Questions