Dashboards & Visualizations

How to change radio selction based on token?

matstap
Communicator

I have a dashboard where a panel with a radio selection is hidden until a selection has been made from a dropdown menu. The problem I'm having is when I select a radio button, hide the panel, then show the panel again the token value for the radio is unset (as desired) but the radio button is still selected.
I want the radio selection to go back to the default when hiding/unhiding the panel.

Here is the xml:

<form>
  <fieldset submitButton="false">
    <input type="dropdown" token="Product">
      <label>Product</label>
      <search>
        <query>some populating query</query>
      </search>
      <fieldForLabel>product</fieldForLabel>
      <fieldForValue>product</fieldForValue>
      <change>
        <condition value="">
          <unset token="Product"></unset>
        </condition>
        <condition match="(value!=&quot;&quot;)">
          <unset token="Reports"></unset>
        </condition>
      </change>
    </input>
  </fieldset>

  <row>
    <panel depends="$Product$">
      <input type="radio" token="Reports">
        <label>Reports</label>
        <choice value="">Select Report</choice>
        <fieldForLabel>search</fieldForLabel>
        <fieldForValue>search</fieldForValue>
        <search>
          <query>some populating query</query>
        </search>
        <change>
          <condition value="">
            <unset token="Reports"></unset>
          </condition>
        </change>
        <default></default>
      </input>
    </panel>
  </row>
</form>
0 Karma
1 Solution

tiagofbmm
Influencer

Ok I believe this does what you want. Choosing "LALA" in the dropdown resets hides the Radio and resets to default when you later choose one of the other dropdown values:

<form>
  <fieldset submitButton="false">
    <input type="dropdown" token="Product">
      <label>Product</label>
      <search>
        <query>index=_internal | head 1000 | dedup source | table source</query>
      </search>
      <fieldForLabel>source</fieldForLabel>
      <fieldForValue>source</fieldForValue>
      <change>
        <!--condition value="LALA">
          <unset token="Product"></unset>
        </condition-->
        <condition value="LALA">
          <set token="Reports"></set>
          <set token="form.Reports"></set>
          <unset token="Product"></unset>
        </condition>
      </change>
      <choice value="LALA">LALA</choice>
    </input>
  </fieldset>
  <row>
    <panel depends="$Product$">
      <input type="radio" token="Reports">
        <label>Reports</label>
        <choice value="">Select Report</choice>
        <fieldForLabel>source</fieldForLabel>
        <fieldForValue>source</fieldForValue>
        <search>
          <query>index=_internal | head 1000 | dedup source | table source</query>
        </search>
        <change>
          <condition value="Select Report"></condition>
        </change>
      </input>
    </panel>
  </row>
</form>

View solution in original post

tiagofbmm
Influencer

Ok I believe this does what you want. Choosing "LALA" in the dropdown resets hides the Radio and resets to default when you later choose one of the other dropdown values:

<form>
  <fieldset submitButton="false">
    <input type="dropdown" token="Product">
      <label>Product</label>
      <search>
        <query>index=_internal | head 1000 | dedup source | table source</query>
      </search>
      <fieldForLabel>source</fieldForLabel>
      <fieldForValue>source</fieldForValue>
      <change>
        <!--condition value="LALA">
          <unset token="Product"></unset>
        </condition-->
        <condition value="LALA">
          <set token="Reports"></set>
          <set token="form.Reports"></set>
          <unset token="Product"></unset>
        </condition>
      </change>
      <choice value="LALA">LALA</choice>
    </input>
  </fieldset>
  <row>
    <panel depends="$Product$">
      <input type="radio" token="Reports">
        <label>Reports</label>
        <choice value="">Select Report</choice>
        <fieldForLabel>source</fieldForLabel>
        <fieldForValue>source</fieldForValue>
        <search>
          <query>index=_internal | head 1000 | dedup source | table source</query>
        </search>
        <change>
          <condition value="Select Report"></condition>
        </change>
      </input>
    </panel>
  </row>
</form>

View solution in original post

matstap
Communicator

This works. Thanks!

I made one change though. I added:

<condition value="*">
          <set token="Reports"></set>
          <set token="form.Reports"></set>
        </condition>

above <condition value="LALA"> to make the Reports reset when switching to other dropdown selections as well.

Thanks again!

0 Karma

tiagofbmm
Influencer

You're welcome 🙂

0 Karma

tiagofbmm
Influencer

Hi

Please use this generic test on your Splunk and adapt it. It is the same as yours but with some concrete values as examples. Let me know if it works for you

<form>
  <fieldset submitButton="false">
    <input type="dropdown" token="Product">
      <label>Product</label>
      <search>
        <query>index=_internal | head 1000 | dedup source | table source</query>
      </search>
      <fieldForLabel>source</fieldForLabel>
      <fieldForValue>source</fieldForValue>
      <change>
        <condition value="LALA">
          <unset token="Product"></unset>
        </condition>
        <condition match="(value=LALA)">
          <unset token="Reports"></unset>
        </condition>
      </change>
      <choice value="LALA">LALA</choice>
    </input>
  </fieldset>
  <row>
    <panel depends="$Product$">
      <input type="radio" token="Reports">
        <label>Reports</label>
        <choice value="">Select Report</choice>
        <fieldForLabel>source</fieldForLabel>
        <fieldForValue>source</fieldForValue>
        <search>
          <query>index=_internal | head 1000 | dedup source | table source</query>
        </search>
        <change>
          <condition value="">
            <unset token="Reports"></unset>
          </condition>
        </change>
        <default></default>
      </input>
    </panel>
  </row>
</form>
0 Karma

matstap
Communicator

I get the same behavior from this. The radio button isn't resetting to "Select Report" when I change the dropdown selection.

0 Karma
.conf21 CFS Extended through 5/20!

Don't miss your chance
to share your Splunk
wisdom in-person or
virtually at .conf21!

Call for Speakers has
been extended through
Thursday, 5/20!