Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keydown error due to conflict with nya-bootstrap-select plugin #1710

Closed
szmalec opened this issue Apr 26, 2017 · 3 comments
Closed

keydown error due to conflict with nya-bootstrap-select plugin #1710

szmalec opened this issue Apr 26, 2017 · 3 comments

Comments

@szmalec
Copy link

szmalec commented Apr 26, 2017

I'am using bootstrap-select AND nya-bootstrap-select on the same page. When I press key down when in searchbox of nya-bootstrap-select then keydown event handler from bootstrap-select is raised which leads to error:

Uncaught TypeError: Cannot read property 'options' of undefined

Error occurs in following line of keydown handler:

if (that.options.liveSearch) $parent = $this.parent().parent();

it occurs because this

that = $parent.data('this')

  • that is assigned to undefined

Problem probably occurs because control is NOT bootstrap-select - it is nya-bootstrap-select which uses bs-searchbox css style for searchbox and as we can see in bootstrap-select source code, this style is used in selector for keydown handler:

  $(document)
      .data('keycount', 0)
      .on('keydown', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input', Selectpicker.prototype.keydown)
      .on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input', function (e) {
        e.stopPropagation();
      });

Can you provide fix for this? I think that in code above, selector should be modified to something like this:

  $(document)
      .data('keycount', 0)
      .on('keydown', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bootstrap-select .bs-searchbox input', Selectpicker.prototype.keydown)
      .on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bootstrap-select .bs-searchbox input', function (e) {
        e.stopPropagation();
      });

@caseyjhol
Copy link
Member

Possibly fixed now that the keydown event is namespaced?

@iantropov
Copy link

Hi @caseyjhol

Possibly fixed now that the keydown event is namespaced?

No, because namespacing of event doesn't affect subscription to keydown event. And now we subscribe to all input in .bs-searchbox containers (https://github.com/silviomoreto/bootstrap-select/blob/master/js/bootstrap-select.js#L1833), but some of them can be placed outside bootstrap select component (may be inside other plugins, like mentioned nya-bootstrap-select).

I think, that we should re-open this issue. Also, if you want, I can prepare PR for this.

iantropov pushed a commit to iantropov/bootstrap-select that referenced this issue Aug 26, 2017
@caseyjhol caseyjhol reopened this Oct 16, 2018
caseyjhol added a commit that referenced this issue Oct 16, 2018
Fix subscription to .bs-searchbox input events (#1710)
caseyjhol added a commit that referenced this issue Oct 16, 2018
Fix subscription to .bs-searchbox input events (#1710)
@caseyjhol
Copy link
Member

Released in v1.13.4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants