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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...