Dashboards & Visualizations

Using EventHandler with MultiSelectInput

tdiestel
Path Finder

I have a multiselect input and i want to create a couple tokens from a single multiselect. This works with single value inputs but for Multiselects inputs it fails.

Here's the scenario: I have a table like this,
name| state | city
tom| CA | SF
mike|CA |TAHOE
mark|AZ | Phoenix

In the multi select you can select from a list of names and the token will be the states. BUT I also want to create a token for the city at the same time. I tried this:

    var input2 = new MultiSelectInput({
        "id": "input2",
        "delimiter": " ",
        "labelField": "name",
        "searchWhenChanged": true,
        "valueField": "state",
        "value": "$form.multi_select2$",
        "managerid": "search5",
        "el": $('#input2')
    }, {tokens: true}).render();

    input2.on("change", function(newValue) {
        FormUtils.handleValueChange(input2);
    });


   input2.on("valueChange", function(e) {
       if (e.value !== undefined) {
           EventHandler.setToken("field2.cityMultiSelect", "$row.city$", {}, e.data);
       }
   });

When I try the above code it will only populate the $field2.cityMultiSelect$ with one city value, even though the user may have selected multiple names. Is there any what to make $field2.cityMultiSelect$ a multi value token as well?

Tags (3)

niketn
Legend

@tdiestel, Since the multiselect value just assigns the first selected value as token and ignores the remaining selected multivalues.
alt text

Following JavaScript can be used to iterate through the multi values and return selected comma separated values.
PS: The example is from HTML Dashboard, but the same can be modified for SplunkJS as well.

    input2.on("valueChange", function(e) {
        var loopCounter;
        for(loopCounter=0;loopCounter<e.data.length;loopCounter++)
        {
            var tmpMultiValue;
            if (e.value[loopCounter] !== undefined) {
                if(tmpMultiValue == undefined){
                    // First time initialize temporary multivalued data
                    tmpMultiValue=e.value[loopCounter];
                }else{
                    // Prepare comma separated multivalued data
                    tmpMultiValue=tmpMultiValue+","+e.value[loopCounter];
                    // Original code untouched. 
                    // Sets first value. If iterated over data objects (cumulative) this might populate multivalued data.
                    EventHandler.setToken("multiSelect", "$value$", {}, e.data);
                }
          }
        }
        // Custom multi valued token multiValue set using SplunkJS Token Handler.
        // May need to change from default to submitted Token handler as required.
        var tokens = mvc.Components.get("default");
        tokens.set("multiValue", tmpMultiValue);
    });

Once multiValue token is populated the same can be passed to a dummy Splunk Search to iterate and split as multi valued using comma and then expanded as single value results.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

niketn
Legend

The change event is not available for multiselect input refer to the documentation: http://docs.splunk.com/Documentation/Splunk/latest/Viz/EventHandlerReference

I wish there was an enhancement to multiselect input to handle change.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

tdiestel
Path Finder

This is very helpful. One thing I don't understand is why would it not be available for the multiselect, but available for the check box, where you can have several options?

I'll test this out and see if it works as i would expect the multiselect to work. Thank you again.

UPDATE: Just tested out the check box input and same results as the multiselect, which is it doesn't work.

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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...