disable items or nested items

Hello,


Is there a way to disable dropdown items when a certain number of items have been selected?, e.g: if I select a total of 20 items, the other items will be disabled


regards


1 Reply

IL Indhumathy Loganathan Syncfusion Team July 5, 2023 08:21 AM UTC

Hi Jean,


Greetings from Syncfusion support.


We have achieved your requirement by using the Dropdown Tree component change event. Within that event, we have added e-disable class to the list items based on the selected items count. Check out the code snippet below.


const onChange = (args) => {

  if (args.value.length > 5) {

    var elements = document.querySelectorAll("[aria-checked='false'");

    for (var i = 0; i < elements.length; i++) {

      //Disable all the other nodes if count is above 5 items.

      elements[i].closest('li').classList.add('e-disable');

    }

  } else {

    var elements = document.querySelectorAll('.e-disable');

    for (var i = 0; i < elements.length; i++) {

      //Enable all the nodes if count is less than 5 items.

      elements[i].classList.remove('e-disable');

    }

  }

};


Sample: https://stackblitz.com/edit/react-jzrgst?file=index.js


Check out the shared sample and get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon