jQWidgets Forums

jQuery UI Widgets Forums General Discussions Lists ListBox select one checkbox at a time?

This topic contains 3 replies, has 2 voices, and was last updated by  Peter Stoev 10 years, 10 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • select one checkbox at a time? #59138

    Adarsha
    Participant

    Hi,
    I have a checkboxes:true inside listbox
    I have 10 items in the list box, and i must be able to select only one checkbox at a time. if i select the 2nd one the previous checked item should be unchecked.

    Thanks!

    select one checkbox at a time? #59147

    Peter Stoev
    Keymaster

    Hi Adarsha,

    I prepared a sample which should do the job.

      var source = [
          "Affogato",
          "Americano",
          "Bicerin",
          "Breve",
          "Café Bombón",
          "Affogato",
          "Americano",
          "Bicerin",
          "Breve",
          "Café Bombón",
          "Café au lait"];
      // Create a jqxListBox
      $("#jqxListBox").jqxListBox({
          source: source,
          theme: 'energyblue',
          selectedIndex: 3,
          checkboxes: true
      });
      $('#jqxListBox').on('checkChange', function (event) {
          var args = event.args;
          if (args) {
              // index represents the item's index.                          
              var index = args.index;
              var item = args.item;
              if (args.checked) {
                  // get item's label and value.
                  var label = item.label;
                  var value = item.value;
                  for (var i = 0; i < source.length; i++) {
                      if (source[i] != label) {
                          $('#jqxListBox').jqxListBox('uncheckIndex', i);
                      }
                  }
              }
          }
      });

    Live demo: http://jsfiddle.net/84h15rb3/

    Hope this helps.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    select one checkbox at a time? #59153

    Adarsha
    Participant

    perfect.. thanks !

    don you think it is good to have a property to handle this scenario ?

    select one checkbox at a time? #59156

    Peter Stoev
    Keymaster

    Hi Adarsha,

    It depends on how many users would want such feature, but for four years, you’re the first one.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.