otterslide
otterslide

Reputation: 560

Jquery File Upload Delete File Programmatically

I'm trying to prevent Jquery fileupload delete until a Bootbox modal popup is answered by the user.

I tried catching fileuploaddestroy and running e.preventDefault() , which works to prevent the delete. But how can I trigger the delete once the user presses OK? I have the "data" object with the delete URL from handling the event.

I tried to call the destroy function directly, but it's not working. the "that" parameter doesn't seem to initialize properly. Also since the event was prevent defaulted, I created a new event..

    var ev = jQuery.Event( "click" );
    $('#fileupload').fileupload('option').destroy(ev, data);

I get

jquery.fileupload-ui.js:399 Uncaught TypeError: Cannot read property 'options' of undefined

Upvotes: 1

Views: 3014

Answers (1)

Avi
Avi

Reputation: 351

Here is an example of how to do this assuming myAsyncConfirm is an async confirm library that will call the passed function on confirmation.

$('#fileupload').bind('fileuploaddestroy', function (e, data) {
  myAsyncConfirm(
    'Are you sure you want to delete file?',
    function() {
      $('#fileupload').fileupload('option', 'destroy').call($('#fileupload'), $.Event('destroy'), data);
    });
  return false;
});

Upvotes: 3

Related Questions