4

How can I disable/enable some option of a select menu before the menu is opned using the selectmenu UI?

I don't see a beforeOpen event in the doc. Is there a way to enable/disable items on the fly?

Junior
  • 11,602
  • 27
  • 106
  • 212

1 Answers1

0

You could do that on open event or before plugin initialization :

$(function(){
  $('select').selectmenu();
  
  
  $('#disable').click(function(){
      $('select option:eq(1)').attr("disabled", true);   

      $('select').selectmenu();
  })
});
/* demo styles */
body {font-size: 62.5%; font-family:"Verdana",sans-serif; }
fieldset { border:0; }  
label,select,.ui-select-menu { float: left; margin-right: 10px; }
select { width: 200px; }    
.wrap span.ui-selectmenu-item-header,
.wrap ul.ui-selectmenu-menu li a { text-decoration: underline !important; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.position.js"></script>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.widget.js"></script>
<link href="http://github.felixnagel.com/selectmenu/themes/base/jquery.ui.theme.css" rel="stylesheet"/>
<link href="http://github.felixnagel.com/selectmenu/themes/base/jquery.ui.core.css" rel="stylesheet"/>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.core.js"></script>
<link href="http://github.felixnagel.com/selectmenu/themes/base/jquery.ui.selectmenu.css" rel="stylesheet"/>
<script src="http://github.felixnagel.com/selectmenu/ui/jquery.ui.selectmenu.js"></script>


<select name="data[sport]" class="selectmenu" id="sport">
  <option value="Kayaking">Kayaking</option>
  <option value="Rock climbing">Rock climbing</option>
  <option value="Surfing">Surfing</option>
  <option value="Skateboarding">Skateboarding</option>
</select>

<button id='disable'>Disable second option</button>
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
  • I need to be able to call a function. My goal is to execute an AJAX call which tells me which items to enable/disable. – Junior Mar 02 '16 at 00:30