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!

Observability | How to Think About Instrumentation Overhead (White Paper)

Novice observability practitioners are often overly obsessed with performance. They might approach ...

Cloud Platform | Get Resiliency in the Cloud Event (Register Now!)

IDC Report: Enterprises Gain Higher Efficiency and Resiliency With Migration to Cloud  Today many enterprises ...

The Great Resilience Quest: 10th Leaderboard Update

The tenth leaderboard update (11.23-12.05) for The Great Resilience Quest is out &gt;&gt; As our brave ...