Splunk Dev

mvc.Components.getInstance("input2"); for multiple inputs?

dt201482
New Member

I have the following code that I am using from this link (modified slightly) to remove or add my All select as needed. Works perfectly for my input 2....but I have 5 more inputs I want it to do the exact same functionality on. I can't really find much documentation on the methods available for mvc.Components, so I can't tell if there is a getClass, or some similar functionality. Anyone have a clue on how I can do below, but for all inputs matching input2 - input8? Relevant code is from line 11 through 34

Edit: Can't add links to answers from this site yet.....

require(['jquery','underscore','splunkjs/mvc', 'website_status_cell_renderer', 'splunkjs/mvc/simplexml/ready!'],
    function($, _, mvc, WebsiteStatusCellRenderer){

        var statusTable = mvc.Components.get('element2');

        statusTable.getVisualization(function(tableView){
            tableView.table.addCellRenderer(new WebsiteStatusCellRenderer());
            tableView.table.render();
        });

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

      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();
              }
          } else if ( selection.length < 1){
            multi.val("*");
            multi.render();
          }
      });


    }
);
Tags (3)
0 Karma
1 Solution

LukeMurphey
Champion

If you know that inputs 2 through 8 need to be modified, you could just use a function to iterate through the inputs accordingly:

       function setupMultiInput(instance_id){
         var multi = mvc.Components.getInstance(instance_id);

         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();
                 }
             } else if ( selection.length < 1){
               multi.val("*");
               multi.render();
             }
         });
       }

       for(var c = 2; c <= 8; c++){
        setupMultiInput("input" + c);
       }

View solution in original post

0 Karma

LukeMurphey
Champion

If you know that inputs 2 through 8 need to be modified, you could just use a function to iterate through the inputs accordingly:

       function setupMultiInput(instance_id){
         var multi = mvc.Components.getInstance(instance_id);

         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();
                 }
             } else if ( selection.length < 1){
               multi.val("*");
               multi.render();
             }
         });
       }

       for(var c = 2; c <= 8; c++){
        setupMultiInput("input" + c);
       }
0 Karma

dt201482
New Member

Thanks. Exactly what I needed. Not sure why I didn't think of it yesterday, brain must have been fried from learning how to do dashboards.

0 Karma

LukeMurphey
Champion

haha, we have all been there :).

BTW: I noticed you are using the WebsiteStatusCellRenderer. May I presume thats one from the Website Monitoring app? I'm just curious if you were making changes to that app or if you were using for something new. Let me know if you need any help with that too.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Data Drivers: How We're Streaming Real-Time F1 Telemetry Directly into Splunk ...

Data Drivers: Every Lap Tells a Story The Spectacle Two F1 racing sims go head-to-head on the .conf26 show ...

Data Management Digest – July 2026

  Welcome to the July 2026 edition of Data Management Digest! As your trusted partner in data innovation, the ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...