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

Autocomplete input box frozen when the form is in bootstrap 3 modal. #715

Closed
wkang0 opened this issue Jul 23, 2016 · 2 comments
Closed

Autocomplete input box frozen when the form is in bootstrap 3 modal. #715

wkang0 opened this issue Jul 23, 2016 · 2 comments

Comments

@wkang0
Copy link

wkang0 commented Jul 23, 2016

I put a form with person and birth_country on a modal form. The Ajax call works fine but the input box was frozen and I can't type anything there.

@wkang0
Copy link
Author

wkang0 commented Jul 25, 2016

@wkang0 wkang0 closed this as completed Jul 25, 2016
@zibertscrem
Copy link

I know this issue still exists. And I found an elegant solution to the bootstrap modal problem. We just "decorate" jquery select2 function and check internally that element is inside a modal, and If so then just patch options with dropdownParent pointing to this modal. And you don't need to catch any DAL's events, everything just started working smoothly

$(document).ready(function () {
  const oldSelect2 = $.fn.select2;
  $.fn.select2 = function (options) {
    const $element = $(this);
    const $modal = $element.parents('.modal:first');
    options = options || {};
    if (typeof options === "object" && $modal.length !== 0) {
      $.extend(options, {dropdownParent: $modal});
    }
    return oldSelect2.apply(this, [options]);
  };
});

P.S. also you may want to do something like this in CSS cause default value could be not enough:

.modal .select2-container {
  z-index: 2000;
}

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

2 participants