jQueryUI - selectable() set to single item

11. August 2010 12:32

The jQueryUI Selectable by default will select multiple items, either by the lasso or by holding the control button.   There is not an option to set the interface for a single item.  So what I have done is on the stop selecting event use a function that will only select the first item of the selected and set the remainder to un-selected.  Continue reading to see the code and a downloadable sample page. 

 

   1:  <script type="text/javascript">
   2:      $(document).ready(function() {
   3:          $("#lstRefresh").selectable({
   4:              stop: function(e, ui) {
   5:                  $(".ui-selected:first", this).each(function() {
   6:                      $(this).siblings().removeClass("ui-selected");
   7:                      var refreshVal = $(this).attr("value");
   8:                      alert(refreshVal);
   9:                  });
  10:              }
  11:          });
  12:      });
  13:  </script>

 

jQueryUISelectableFirst.html (2.47 kb)

Comments are closed