Dashboards & Visualizations

Can we limit the number of choices in the multiselect input?

pkphmdw
New Member

Can we limit the number of choices in the multiselect input?
I want to have an input as multiselect built from a search and limit the number of select e.g. to 2.

0 Karma

maciep
Champion

Not sure if there is an actual option for that in simple xml, but maybe something like this?

Doesn't seem to work without enabling search on change, but could be something i'm missing there. It's the change tag that decides whether new items are allowed. Essentially after the user adds a 3rd, we change it back to only the first 2. Could also keep the last and remove the first if you wanted.

<input type="multiselect" token="t_comp" searchWhenChanged="true">
  <label>Component</label>
  <search>
    <query>index=_internal | stats count by component</query>
    <earliest>-60m@m</earliest>
    <latest>now</latest>
  </search>
  <change>
    <eval token="form.t_comp">if(mvcount('form.t_comp')=3, mvindex('form.t_comp',0,1),'form.t_comp')</eval>
  </change>
  <fieldForLabel>component</fieldForLabel>
  <fieldForValue>component</fieldForValue>
  <delimiter> OR </delimiter>
  <prefix>(</prefix>
  <suffix>)</suffix>
  <valuePrefix>component = "</valuePrefix>
  <valueSuffix>"</valueSuffix>
</input>

And of course if you only want to limit to 2, you could also just build 2 dropdowns.

pkphmdw
New Member

awesome. thanks. I adjusted the eval with a different token name to make it work.

0 Karma

maciep
Champion

great, glad to help...don't forget to accept the answer too

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...