bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Fileinput does not work with refile gem

Open jemminger opened this issue 9 years ago • 4 comments

It appears that the call to e.stopPropagation() breaks the "direct" upload functionality of Refile. Refile is listening to the change event on document, and this call prevents it from bubbling.

Is there a reason why the change event should not bubble?

jemminger avatar Apr 01 '15 16:04 jemminger

From a quick look at the code, it stops because later on it fires a change.bs.fileinput event at the wrapper div level. It fires from the div that has this data attribute data-provides="fileinput".

I can see how third party plugins may not work if they're listen to this event at the document level for actual file inputs. For you, the only thing I can come up with is a workaround which is to remove the e.stopPropagation() and also the triggering of change.bs.fileinput event so that it bubble up. As for this plugin, @jasny may have some idea for a real solution so that it mitigate issues with third party plugins.

ducman avatar Apr 01 '15 17:04 ducman

Yeah, for now I'm just running my own version with e.stopPropagation() commented out, and it seems to work as expected.

jemminger avatar Apr 01 '15 17:04 jemminger

Noted, have to think about it...

jasny avatar Apr 02 '15 05:04 jasny

I have the same issue. Thanks for your suggestions. To keep original code unchanged I have overrided the original method like that:

$(function() {
  // Override jasny Fileinput.prototype.change method
  function change(e) {
    // copy/paste original function and comment out e.stopPropagation()
  }

  $(document).on('click.fileinput.data-api', '[data-provides="fileinput"]', function (e) {
    var self = $(this),
        input = self.find(':file'),
        plugin = self.data('bs.fileinput');

    input.off('change.bs.fileinput').on('change.bs.fileinput', $.proxy(change, plugin))
  })
});

oliveiragabriel07 avatar Sep 08 '15 01:09 oliveiragabriel07