error with a select2 in front of a modal

0

I have the following problem, when selecting the select2, the options are shown below the modal hiding from the user's view, some way of solving it and showing it in front of the modal?

Try the following code:

.select2{
  z-index: 999999;
}

But it did not work.

    
asked by Raphael 01.12.2017 в 00:19
source

1 answer

1

In general, when a modal is opened, it appropriates the events related to clicks and keys (for example, to close when you press ESC or ENTER).

Since select2 creates its dynamic html in the body and is out of the modal, it is not taken into account. For this, you must use the option dropdownParent passing it the ID of your modal:

$('#mySelect2').select2({
  dropdownParent: $('#myModal')
});

With that the content of the dropdown of select2 is inside the DOM node of the modal and should work well.

    
answered by 01.12.2017 / 00:57
source