Dashboards & Visualizations
Highlighted

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

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
Highlighted

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

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
Highlighted

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

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
Highlighted

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

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