bootstrap: Error when calling $('.fileinput').fileinput('reset')

Everytime I call $('.fileinput').fileinput('reset') I get this error SyntaxError: Invalid regular expression: /(^|\.)bs\.(?:.*\.|)fileinput(\.|$)/: Stack overflow. Does anybody know what could be causing this?

I am on Bootstrap 3.0.3, Download the Extend version of Jasny/bootstrap and am using the Input File control.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 22 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Can we please get this fixed. This has been open for over year. Easy solution: just rename the event to resetted.bs.fileinput or getting rid of the event entirely. After all one could still listen to the form’s resetevent if need be.

The file input code is listening for a form reset with the event type of reset.bs.fileinput. When that happen, it calls the reset() function which at the end trigger a reset on the .fileinput element with the same event type reset.bs.fileinput. This, as you already know, causes an infinite loop/recursion, aka stack overflow.

I’m unsure of the best way to solve this but here are 2 ways:

  • Change the triggering event type reset.bs.fileinput to something else to avoid the listening & triggering collision.
  • Or before triggering the reset, stop listening for the form reset then do the trigger then start listening for the form reset again (see below).
Fileinput.prototype.reset = function() {
    // ... existing code stay the same (except for last line)

    $(this.$input[0].form).off('reset.bs.fileinput')  // stop listening
    this.$element.trigger('reset.bs.fileinput')
    $(this.$input[0].form).on('reset.bs.fileinput', $.proxy(this.reset, this)) // restart listening
 },