Dashboards & Visualizations

How to make the first available value in a 2nd drop-down be selected by default when the first drop-down selection changes?

Divya_B07
New Member

Hi All,

I have two drop-downs where the 2nd drop-down is populated based on the value selected in the 1st drop-down.
Please let me know how to make the first available value in the 2nd drop-down to be selected by default when the 1st drop-down selection changes. Currently the old selected value is retained in the 2nd drop-down when the 1st drop-down value is updated.

NOTE : This issue does not occur on page load because of selectFirstChoice, but happens on subsequent changes.

Eg : 2nd drop-down has {A,B,C} and A is selected on page load. When 1st drop-down is updated, 2nd drop down has {X,Y,Z} values, but still A is retained as the default value.

Thanks in advance!

0 Karma
1 Solution

dkeck
Influencer

Hi,

I am not sure I got the problem correctly, but

I build a test dashboard with sourcettype and depending sources.

So first Dropdown is sourcettypes with a default value. Second Dropdown contains the sources related to the selected sourcetype.

Looks like this : index=_internal sourcetype="$tok_sourcetype$" | top source

Thats what you allready got, right?

So if you also set one of the sources of the default sourcetype as default in the source dropdown. It will automatically set the first value in source as default in the dropdown, when you change the value in the first dropdown.

Also you have to activate "Search on Change".

Is that what you are looking for?

Kind Regards

View solution in original post

0 Karma

dkeck
Influencer

Hi,

I am not sure I got the problem correctly, but

I build a test dashboard with sourcettype and depending sources.

So first Dropdown is sourcettypes with a default value. Second Dropdown contains the sources related to the selected sourcetype.

Looks like this : index=_internal sourcetype="$tok_sourcetype$" | top source

Thats what you allready got, right?

So if you also set one of the sources of the default sourcetype as default in the source dropdown. It will automatically set the first value in source as default in the dropdown, when you change the value in the first dropdown.

Also you have to activate "Search on Change".

Is that what you are looking for?

Kind Regards

0 Karma

Divya_B07
New Member

The following steps fixed the issue.

  1. Addition of true to the second dropdown.
  2. Unset the second dropdown selection when the first dropdown selection changes.

Given below is the snippet:

    <label>First Dropdown:</label>
    <search>
      <query>……. </query>
    </search>
    <fieldForLabel> First Dropdown</fieldForLabel>
    <fieldForValue> First Dropdown</fieldForValue>
    <default>A</default>
     **<change>
         <unset token="form. second_dropdown "></unset>
     </change>**
  </input>
  <input type="dropdown" token="second_dropdown" searchWhenChanged="true">
    <label>Second Dropdown:</label>
    <search>
      <query>…….. </query>
    </search>
    <fieldForLabel> Second Dropdown</fieldForLabel>
    <fieldForValue> Second Dropdown</fieldForValue>
    **<selectFirstChoice>true</selectFirstChoice>**

Thanks!

0 Karma

dkeck
Influencer

If you want to test it, this could help

 <form>
  <label>test dropdown</label>
  <fieldset submitButton="false" autoRun="false">
    <input type="dropdown" token="tok_sourcetype">
      <label>field1</label>
      <search>
        <query>index=_internal| top limit=20 sourcetype</query>
      </search>
      <fieldForLabel>sourcetype</fieldForLabel>
      <fieldForValue>sourcetype</fieldForValue>
      <default>splunkd</default>
    </input>
    <input type="dropdown" token="field2" searchWhenChanged="true">
      <search>
        <query>index=_internal sourcetype="$tok_sourcetype$" | top source</query>
      </search>
      <fieldForLabel>source</fieldForLabel>
      <fieldForValue>source</fieldForValue>
      <default>/opt/splunk/var/log/splunk/metrics.log</default>
    </input>
  </fieldset>
</form>
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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