Dashboards & Visualizations

Remove ALL from multi-select input once any value is selected

Karthikeya
Communicator

Hello,

I have a requirement in dashboard. My multiselect input should remove ALL (default value) if I select any value other than that automatically and ALL should return if I deselect the selected value... Please help me to get this result?

<input type="multiselect" token="app_name">
<label>Application Name</label>
<choice value="*">All</choice>
<default>*</default>
<initialValue>*</initialValue>
<fieldForLabel>app_name</fieldForLabel>
<fieldForValue>app_name</fieldForValue>

<search base="base_search">
<query> |stats count by app_name </query>
</search>
<valuePrefix>app_name="</valuePrefix>
<valueSuffix>"</valueSuffix>
<delimiter> OR </delimiter>
</input>

Labels (6)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try like this - note that your search needs to use the $app_name_choice$ token not $app_name$

    <input type="multiselect" token="app_name">
      <label>Application Name</label>
      <choice value="All">All</choice>
      <default>All</default>
      <initialValue>*</initialValue>
      <fieldForLabel>app_name</fieldForLabel>
      <fieldForValue>app_name</fieldForValue>
      <search base="base_search">
        <query> |stats count by app_name </query>
      </search>
      <valuePrefix>app_name="</valuePrefix>
      <valueSuffix>"</valueSuffix>
      <delimiter> OR </delimiter>
      <change>
        <eval token="form.app_name">case(mvcount('form.app_name')=0,"All",mvcount('form.app_name')&gt;1 AND mvfind('form.app_name',"All")&gt;0,"All",mvcount('form.app_name')&gt;1 AND mvfind('form.app_name',"All")=0,mvfilter('form.app_name'!="All"),1==1,'form.app_name')</eval>
        <eval token="app_name_choice">if('form.app_name'=="All","app_name=\"*\"",'app_name')</eval>
      </change>
    </input>

View solution in original post

marycordova
SplunkTrust
SplunkTrust

I don't think you actually want to remove "ALL" from the multi-select...it makes it so people can go back to the default when they are done with whatever choice they made originally.  I would say if you don't want people to go back to the default...then maybe you don't it there at all in the first place?  Or maybe you don't actually want a multi-select but just a regular drop-down list?  But it seems to me if you want it there in the first place, you actually want it there always so people can revert back to the default behavior of the dashboard when they are done messing around 😊 (IMO).

@marycordova
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You can do this without javascript - here is a SimpleXML example

    <input type="multiselect" token="alloptions" searchWhenChanged="true">
      <label>Options $alloptions$</label>
      <choice value="All">All</choice>
      <search>
        <query>
| makeresults count=20
| streamstats count as row
| eval option="Option ".mvindex(split("ABCDEFGHIJKLMNOPQRSTUVWXYZ",""),row-1)
| eval label="Option ".mvindex(split("abcdefghijklmnopqrstuvwxyz",""),row-1)
| table option label
        </query>
      </search>
      <fieldForLabel>label</fieldForLabel>
      <fieldForValue>option</fieldForValue>
      <delimiter>,</delimiter>
      <change>
        <eval token="form.alloptions">case(mvcount('form.alloptions')=0,"All",mvcount('form.alloptions')&gt;1 AND mvfind('form.alloptions',"All")&gt;0,"All",mvcount('form.alloptions')&gt;1 AND mvfind('form.alloptions',"All")=0,mvfilter('form.alloptions'!="All"),1==1,'form.alloptions')</eval>
      </change>
    </input>

 

0 Karma

Karthikeya
Communicator

Here is my existing multiselect XML..

<input type="multiselect" token="app_name">

<label>Application Name</label>

<choice value="*">All</choice>

<default>*</default>

<initialValue>*</initialValue>

<fieldForLabel>app_name</fieldForLabel>

<fieldForValue>app_name</fieldForValue>

 

<search base="base_search">

<query> |stats count by app_name </query>

</search>

<valuePrefix>app_name="</valuePrefix>

<valueSuffix>"</valueSuffix>

<delimiter> OR </delimiter>

</input>

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try like this - note that your search needs to use the $app_name_choice$ token not $app_name$

    <input type="multiselect" token="app_name">
      <label>Application Name</label>
      <choice value="All">All</choice>
      <default>All</default>
      <initialValue>*</initialValue>
      <fieldForLabel>app_name</fieldForLabel>
      <fieldForValue>app_name</fieldForValue>
      <search base="base_search">
        <query> |stats count by app_name </query>
      </search>
      <valuePrefix>app_name="</valuePrefix>
      <valueSuffix>"</valueSuffix>
      <delimiter> OR </delimiter>
      <change>
        <eval token="form.app_name">case(mvcount('form.app_name')=0,"All",mvcount('form.app_name')&gt;1 AND mvfind('form.app_name',"All")&gt;0,"All",mvcount('form.app_name')&gt;1 AND mvfind('form.app_name',"All")=0,mvfilter('form.app_name'!="All"),1==1,'form.app_name')</eval>
        <eval token="app_name_choice">if('form.app_name'=="All","app_name=\"*\"",'app_name')</eval>
      </change>
    </input>

Karthikeya
Communicator

@ITWhisperer thanks for the code. It is working but my doubt as per your comment - do I replace $app_name$ token with $app_name_choice$ in all my panels? Because even though I didn't change my panels are refreshing at the moment according to multiselect options given. Please confirm do I need to replace?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You probably do need to use app_name_choice in your panels if you want the All option to be converted to * otherwise your search will be for app_name="All" which is probably not what you want!

0 Karma

Karthikeya
Communicator

@ITWhisperer thanks for the reply. Where I need to give this input? In my existing multiselect input?

0 Karma

Karthikeya
Communicator

In which component ( I mean deployer or direct search head) I need to give this JS? can you please specify full path?

0 Karma

livehybrid
Champion

Hi @Karthikeya 

To achieve this you are probably best using some Javascript, have a look at these two links as I think they contain working examples for you to use:

https://community.splunk.com/t5/Dashboards-Visualizations/Remove-quot-All-quot-from-Multiselect-Inpu...

https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-rid-of-default-quot-All-quot-fr...

 

 

Please let me know how you get on and consider upvoting/karma this answer if it has helped.
Regards

Will

livehybrid
Champion

Essentially you need to create the following in a allSelect.js file in appname/appserver/static:

 

require([
     'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/simplexml/ready!'
 ], function($, mvc){
         $('#multi').on("change",function(){
                 var multi1 = mvc.Components.get("multi");
                 var tokens = mvc.Components.getInstance("default");
                 var mytoken = tokens.get("multi")

                  if (mytoken.length > 1 && mytoken.includes("All"))
                 {
                     // If "All" was selected before current (more specific) selection, remove it from list
                     if (indexOfAll == 0) 
                     {
                         var temp = mytoken.split(" ")
                         var temp1 = temp[1]
                         multi1.val(temp1);
                     } else 
                     {
                         // "All" was selected last, clear input and leave only "All" in it
                         multi1.val("All");
                     }
                 }


 }); 
 }); 

 

Then update the first line of your dashboard to something like this:

<form script="allSelect.js">

 

Get Updates on the Splunk Community!

Developer Spotlight with Brett Adams

In our third Spotlight feature, we're excited to shine a light on Brett—a Splunk consultant, innovative ...

Index This | What can you do to make 55,555 equal 500?

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

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...