Dashboards & Visualizations

How do I hide a dropdown based on a checkbox value in a Splunk dashboard?

AnmolKohli
Explorer

I have 2 dropdowns in a panel and I want to show them based on the value of a checkbox defined in the same dashboard. Can someone please let me know the changes required in XML for the same?

Checkbox :

ValueA
ValueB

If we choose valueA - Dropdown1 should be displayed
if we choose valueB - Dropdown2 should be displayed

Thanks

0 Karma
1 Solution

493669
Super Champion

Hi @AnmolKohli,
Try below :

<fieldset submitButton="false">
      <input type="checkbox" token="view">
        <label>View</label>
          <choice value="ValueA">ValueA</choice>
        <choice value="ValueB">ValueB</choice>
        <default>site</default>
        <change>
          <condition value="ValueA">
              <set token="A">true</set>
              <unset token="B"></unset>
            </condition>
            <condition value="ValueB">
              <set token="B">true</set>
              <unset token="A"></unset>
            </condition>
        </change>
      </input>
      <input type="dropdown" token="test" depends="$A$" >
        <label>dropdown 1</label>
        <choice value="data1">Data1</choice>
        <choice value="data2">Data2</choice>
      </input>
      <input type="dropdown" token="test2" depends="$B$" >
        <label>dropdown 2</label>
        <choice value="data3">Data3</choice>
        <choice value="data4">Data4</choice>
      </input>
    </fieldset>

Here as per checkbox value it will set and unset token and dropdown will be depends on these token to hide or show ...this is not yet tested but you will get an idea

View solution in original post

niketn
Legend

@AnmolKohli , if you need to select only on check box and accordingly only display one Dropdown the solution by @493669 should work. However, if this is actually your use case ideally you should be using Radio button instead of check box which will allow you to select only one option at a time.

With checkbox users will have option to choose both values A and B, which is when the above solution will not work. You would need to use independent search to set/unset the the required tokens based on multiple selections. Refer to following answer on Similar lines: https://answers.splunk.com/answers/681330/can-i-hideunhide-specific-text-boxes-using-a-singl.html

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

493669
Super Champion

Hi @AnmolKohli,
Try below :

<fieldset submitButton="false">
      <input type="checkbox" token="view">
        <label>View</label>
          <choice value="ValueA">ValueA</choice>
        <choice value="ValueB">ValueB</choice>
        <default>site</default>
        <change>
          <condition value="ValueA">
              <set token="A">true</set>
              <unset token="B"></unset>
            </condition>
            <condition value="ValueB">
              <set token="B">true</set>
              <unset token="A"></unset>
            </condition>
        </change>
      </input>
      <input type="dropdown" token="test" depends="$A$" >
        <label>dropdown 1</label>
        <choice value="data1">Data1</choice>
        <choice value="data2">Data2</choice>
      </input>
      <input type="dropdown" token="test2" depends="$B$" >
        <label>dropdown 2</label>
        <choice value="data3">Data3</choice>
        <choice value="data4">Data4</choice>
      </input>
    </fieldset>

Here as per checkbox value it will set and unset token and dropdown will be depends on these token to hide or show ...this is not yet tested but you will get an idea

AnmolKohli
Explorer

Worked 🙂 Thanks

0 Karma

richgalloway
SplunkTrust
SplunkTrust

@AnmolKohli If your problem is resolved, please accept an answer to help future readers.

---
If this reply helps you, Karma would be appreciated.
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!

A Four-Part Event Series: Full Stack Observability For the AI Era

As AI reshapes applications, infrastructure, and the way teams operate, the traditional boundaries of ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...