Dashboards & Visualizations

selectFirstChoice not working in dynamic dropdowns after update of generating search

Muryoutaisuu
Communicator

Hi guys

I have three form inputs. The last two are dynamic dropdowns. Their values are generated with a search, in which the value from the first input is used. The dropdowns are configured to always select the first choice

<selectFirstChoice>true</selectFirstChoice>

Whenever I change the first input, the two other dynamic dropdowns are regenerated. Unfortunately the dropdown's selected choice goes empty, instead of choosing the first available value.

Has someone else experienced the same? Or can someone provide me with a workaround?
Thank you

1 Solution

rphillips_splun
Splunk Employee
Splunk Employee

You can set this for the dropdown:

<change>
    <unset token="form.dropdown"></unset>
</change>

example dashboard

<form script="simple_xml_examples:showtokens.js"> 
  <label>selectfirstchoice</label> 
  <fieldset submitButton="false" autoRun="true"> 
    <input type="dropdown" token="dropdown" searchWhenChanged="true"> 
      <!--<choice value="foo">Foo</choice>--> 
      <search> 
        <query>index=$index$ | head 200 | stats count by sourcetype</query> 
      </search> 
      <fieldForLabel>sourcetype</fieldForLabel> 
      <fieldForValue>sourcetype</fieldForValue> 
      <selectFirstChoice>true</selectFirstChoice>
    </input> 
    <input type="text" token="index" searchWhenChanged="true">
      <change>
        <unset token="form.dropdown"></unset>
      </change>
    </input> 
    <input type="time" token="field1" searchWhenChanged="true"> 
      <label></label> 
      <default> 
        <earliest>-15m</earliest> 
        <latest>now</latest> 
      </default> 
    </input> 
  </fieldset> 
  <row> 
    <panel> 
      <chart> 
        <search> 
          <query>index=_internal | timechart count</query> 
          <earliest>$field1.earliest$</earliest> 
          <latest>$field1.latest$</latest> 
        </search> 
        <option name="charting.chart">line</option> 
      </chart> 
    </panel> 
  </row> 
</form>

View solution in original post

rphillips_splun
Splunk Employee
Splunk Employee

You can set this for the dropdown:

<change>
    <unset token="form.dropdown"></unset>
</change>

example dashboard

<form script="simple_xml_examples:showtokens.js"> 
  <label>selectfirstchoice</label> 
  <fieldset submitButton="false" autoRun="true"> 
    <input type="dropdown" token="dropdown" searchWhenChanged="true"> 
      <!--<choice value="foo">Foo</choice>--> 
      <search> 
        <query>index=$index$ | head 200 | stats count by sourcetype</query> 
      </search> 
      <fieldForLabel>sourcetype</fieldForLabel> 
      <fieldForValue>sourcetype</fieldForValue> 
      <selectFirstChoice>true</selectFirstChoice>
    </input> 
    <input type="text" token="index" searchWhenChanged="true">
      <change>
        <unset token="form.dropdown"></unset>
      </change>
    </input> 
    <input type="time" token="field1" searchWhenChanged="true"> 
      <label></label> 
      <default> 
        <earliest>-15m</earliest> 
        <latest>now</latest> 
      </default> 
    </input> 
  </fieldset> 
  <row> 
    <panel> 
      <chart> 
        <search> 
          <query>index=_internal | timechart count</query> 
          <earliest>$field1.earliest$</earliest> 
          <latest>$field1.latest$</latest> 
        </search> 
        <option name="charting.chart">line</option> 
      </chart> 
    </panel> 
  </row> 
</form>

jcloudpld
New Member

I have a similar scenario with two dropdowns. This solution mostly worked for me. The only issue is that when I first navigate to the page, the second dropdown is empty until the user either: A) Refreshes the page, or B) Changes the first dropdown's selection.

For clarity, this only seems to happen the first time I navigate to my dashboard either from the dashboard selection or after saving edits to the simpleXML.

I believe the issue is that the second dropdown is being populated and then the first dropdown is calling the tag and leaving the second dropdown unpopulated until the user changes the first dropdown again. It's worth noting that I've tried setting selectFirstChoice to true for both, and true for just the second dropdown.

Has anyone else experienced something similar that would be able to offer up a solution/advice?

0 Karma

sk314
Builder

Thank you, Kind Sir. This turned out to be trickier than I expected.

0 Karma

kkrishnan_splun
Splunk Employee
Splunk Employee

Works beautifully !! Is there any way that the dropdown value can be reset to its default value?

0 Karma

blhuynh
Explorer

This worked for me although I was confused at first by the ordering but it's that the dropdown gets auto-reset and reselected each time index is changed.

0 Karma

msamelson
Engager

This worked like a charm. Thanks!

0 Karma

somesoni2
Revered Legend

I guess that works just on the first load of the dashboard. If the underlying data source for the dropdown is changed some how, it's ignoring the updated first value.

0 Karma

hemalalli
Explorer
0 Karma

Muryoutaisuu
Communicator

Converting to HTML is no option for us. Our users then would not be possible to make any further changes to the dashboard. I am sorry, but that is no solution for us.

0 Karma

asherman
Path Finder

I see the same issue. When I update a dropdown menu, the ones that depend on it and use the selectFirstChoice flag will update their contents, but not change the actual parameter.

E.g.,
Menu contains {0,5,10}, selects '0'. After updating another menu, it now contains {5, 10, 15}, but still sits on '0'.

This makes the feature somewhat useless.

*NEW* Splunk Love Promo!
Snag a $25 Visa Gift Card for Giving Your Review!

It's another Splunk Love Special! For a limited time, you can review one of our select Splunk products through Gartner Peer Insights and receive a $25 Visa gift card!

Review:





Or Learn More in Our Blog >>