problem when using jquery.select2 in a popup
See original GitHub issueHey,
when using jquery.select2 inside a popup, you can’t type into the select2’s searchbox. There seems to be some kind of focus/blur loop. I have described the issue in more detail here: http://stackoverflow.com/questions/19990191/select2-in-magnific-popup-search-input-cannot-be-focused. Here is jsfiddle that shows the problem: http://jsfiddle.net/clime/qweWa/15/. I have tracked the problem to the following code in magnific popup:
setTimeout(function() {
if(mfp.content) {
mfp._addClassToMFP(READY_CLASS);
_setFocus();
} else {
// if content is not defined (not loaded e.t.c) we add class only for BG
mfp.bgOverlay.addClass(READY_CLASS);
}
// Trap the focus in popup
_document.on('focusin' + EVENT_NS, function (e) {
if( e.target !== mfp.wrap[0] && !$.contains(mfp.wrap[0], e.target) ) {
_setFocus();
return false;
}
});
}, 16);
_setFocus is called indefinietly when select2 is clicked on in a popup.
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Common problems - The jQuery replacement for select boxes
Select2 does not function properly when I use it inside a Bootstrap modal. ... This issue occurs because Bootstrap modals tend to steal...
Read more >Select2 doesn't work when embedded in a bootstrap modal
According to the official select2 documentation this issue occurs because Bootstrap modals tend to steal focus from other elements outside of the modal....
Read more >Select2 search input not working in Bootstrap Modal · Issue #41
You can fix this by removing the tabindex attribute from the .modal . This will allow moving around in the Select2 box, but...
Read more >Bootstrap modal form validation not working with select2
I am using bootstrap modal form calling a partialview from Index.cshtml. It's work fine until I use Select2. The same partialview working ...
Read more >Select2 and Bootstrap Integration by Keenthemes
Select2's is globally initialized through data-control="select2" HTML attribute as defined in src/js/layout/app.js and some options can be be passed through ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The sample code should be updated for the new Select2 v4.x className.
A more future-proof solution may involve searching for “select2” anywhere in the class attribute.
Simply add following code
$(function () { $(‘.class-name’).magnificPopup({ callbacks: { open: function(){ $(‘.mfp-wrap’).css(“overflow”, “initial”) $(‘.mfp-wrap’).removeAttr(‘tabindex’) }, }, }); });