Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI selectmenu not working in dialog

The select wont open when inside of a table inside of the dialog. I included a code snippet of the problem

$('select').selectmenu();
$('.RegularDialog').dialog({
  autoOpen: false,
  modal: true,
  height: 500,
  width: 570
});
$('#OpenDialog').click(function(e) {
  $('.RegularDialog').dialog('open');
});
<head>
  <link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
</head>

<body>
  <div id="Dialog" title="Edit Dialog" class="RegularDialog">
    <form action="">
      <table>
        <tr>
          <td>Select the Type</td>
          <td>
            <select id="Type">
              <option value="a">Type 1</option>
              <option value="b">Type 2</option>
              <option value="c">Type 3</option>
            </select>
          </td>
        </tr>
      </table>
    </form>
  </div>

  <button id="OpenDialog">Open Dialog</button>
</body>
like image 954
Nick Avatar asked Feb 10 '15 20:02

Nick


People also ask

Why is my drop down menu not working in jQuery UI?

The problem is that jQuery UI is generating the "drop-down" for the select on the page, but this is outside the div that becomes your popup. Then when the dialog is displayed, it covers the "drop-down". If you move the selectmenu () call to after the dialog appears, it works correctly.

How to hide selectmenu dropdown items after click in jQuery dialog?

2) In Jquery 1.10 there is breaking changes, so dialogs z-index is recalculating on the fly. This hides selectmenu dropdown items after clicking somewhere inside dialog. To fix both, you could just append selectmenu to some empty div before body:

How to increase z-index of selectmenu in jQuery dialog?

2) In Jquery 1.10 there is breaking changes, so dialogs z-index is recalculating on the fly. This hides selectmenu dropdown items after clicking somewhere inside dialog. To fix both, you could just append selectmenu to some empty div before body: And make a z-index of selectmenu significantly higher than dialog ui-front layout.

What is the default functionality of the Ui dialog?

jQuery UI Dialog - Default functionality. Basic dialog. This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.


1 Answers

The problem is that jQuery UI is generating the "drop-down" for the select on the page, but this is outside the div that becomes your popup. Then when the dialog is displayed, it covers the "drop-down".

If you move the selectmenu() call to after the dialog appears, it works correctly.

Your snippet updated:

$('.RegularDialog').dialog({
  autoOpen: false,
  modal: true,
  height: 500,
  width: 570
});
$('#OpenDialog').click(function(e) {
  $('.RegularDialog').dialog('open');
  $('select').selectmenu();
});
<head>
  <link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
</head>

<body>
  <div id="Dialog" title="Edit Dialog" class="RegularDialog">
    <form action="">
      <table>
        <tr>
          <td>Select the Type</td>
          <td>
            <select id="Type">
              <option value="a">Type 1</option>
              <option value="b">Type 2</option>
              <option value="c">Type 3</option>
            </select>
          </td>
        </tr>
      </table>
    </form>
  </div>

  <button id="OpenDialog">Open Dialog</button>
</body>
like image 74
CupawnTae Avatar answered Oct 13 '22 00:10

CupawnTae