Dashboards & Visualizations

Multiselection remove ALL option when others value is picked not working on the both multi-select

DataOrg
Builder

I have two multiselect option in dashboard, with same functionality, when "ALL" options is selected other values will be reset . only either one of the dropdown is working and other is not working when unset token is used

XML code:

<input type="multiselect" token="NAME" id="ALL_RESET" searchWhenChanged="false">
         <label>Select Site</label>
         <fieldForLabel>Name</fieldForLabel>
         <fieldForValue>Name</fieldForValue>
         <search>
           <query>| inputlookup </query>
         </search>
         <change>
           <unset token="form.Brand"></unset>
         </change>
         <choice value="*">---All Brand---</choice>
         <valuePrefix>"</valuePrefix>
         <valueSuffix>"</valueSuffix>
         <delimiter>,</delimiter>
       </input>

<input type="multiselect" token="Brand" id="SERVER_RESET"  searchWhenChanged="false">
         <label>Select Server(s)</label>
         <search id="SERVER_RESET">
           <query>| inputlookup </query>
         </search>
         <fieldForLabel>BRANDNAME</fieldForLabel>
         <fieldForValue>BRANDNAME</fieldForValue>
         <delimiter>,</delimiter>
         <choice value="*">---All BRANDNAME---</choice>

       </input>

JAvascript:

var selection = [];
var multi = splunkjs.mvc.Components.getInstance("ALL_RESET");

  multi.on("change", function(){
      // get the current selection
      selection = multi.val();
      // check if there is more than one entry and one of them is "*"
      if (selection.length > 1 && ~(selection.indexOf("*"))) {
          if (selection.indexOf("*") == 0) {
              // "*" was first, remove it and leave rest
              selection.splice(selection.indexOf("*"), 1);
              multi.val(selection);
              multi.render();
          } else {
              // "*" was added later, remove rest and leave "*"
              multi.val("*");
              multi.render();
          }
      }
  });

var selection = [];
  var multi = splunkjs.mvc.Components.getInstance("SERVER_RESET"); 

  multi.on("change", function(value){
      // get the current selection
      selection = multi.val();
      // check if there is more than one entry and one of them is "*"
      if (selection.length > 1 && ~(selection.indexOf("*"))) {
          if (selection.indexOf("*") == 0) {
              // "*" was first, remove it and leave rest
              selection.splice(selection.indexOf("*"), 1);
              multi.val(selection);
              multi.render();
          } else {
              // "*" was added later, remove rest and leave "*"
              multi.val("*");
              multi.render();
          }
      }
  });
0 Karma
1 Solution

niketn
Legend

@premranjithj correct approach would be to name the multi select object in JS separately as mvc.Components.get() is invoked only once hence only the second multi select in your code would work.

Ideally, you should create an array of multiselect IDs like ALL_RESET, SERVER_RESET and loop through IDs to identify on change event handler for each. However, I will let you figure that out first. Meanwhile try the following code and confirm.

   var multiAll = splunkjs.mvc.Components.getInstance("ALL_RESET");

   multiAll.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiAll.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiAll.val(selection);
               multiAll.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiAll.val("*");
               multiAll.render();
           }
       }
   });

   var multiServer = splunkjs.mvc.Components.getInstance("SERVER_RESET"); 

   multiServer.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiServer.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiServer.val(selection);
               multiServer.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiServer.val("*");
               multiServer.render();
           }
       }
   });
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@premranjithj correct approach would be to name the multi select object in JS separately as mvc.Components.get() is invoked only once hence only the second multi select in your code would work.

Ideally, you should create an array of multiselect IDs like ALL_RESET, SERVER_RESET and loop through IDs to identify on change event handler for each. However, I will let you figure that out first. Meanwhile try the following code and confirm.

   var multiAll = splunkjs.mvc.Components.getInstance("ALL_RESET");

   multiAll.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiAll.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiAll.val(selection);
               multiAll.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiAll.val("*");
               multiAll.render();
           }
       }
   });

   var multiServer = splunkjs.mvc.Components.getInstance("SERVER_RESET"); 

   multiServer.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiServer.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiServer.val(selection);
               multiServer.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiServer.val("*");
               multiServer.render();
           }
       }
   });
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...