Dashboards & Visualizations

How to link radio input with text input in Simple XML?

clairebesson
Explorer

Hi everyone,

I have created a search by Serial Number and a search by Purchase Order with two text inputs. I have also created a radio input with these two fields : "Serial Number" and "Purchase order".
I want to link the radio fields with the text input, meaning, when I click on "Serial Number" on the radio input, it should display the text input "Search by Serial Number". (Same thing for Purchase Order)
Here is my xml code:

<form>
  <label>table</label>
  <fieldset autoRun="true" submitButton="false">
    <input type="text" token="serial_number_token" searchWhenChanged="true">
      <label>Enter a SN</label>
      <default>*</default>
      <suffix></suffix>
    </input>
    <input type="text" token="purchase_order_token" searchWhenChanged="true">
      <label>Enter a Purchase Order</label>
      <default>*</default>
      <suffix></suffix>
    </input>
    <input type="radio" token="field1">
      <choice value="Serial Number">Serial Number</choice>
      <choice value="Purchase Order">PO</choice>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <search>
          <query>source="number.csv" "Serial Number"=$serial_number_token$ "Purchase Order"="$purchase_order_token$"</query>
          <earliest></earliest>
          <latest></latest>
        </search>

Could you please help me with that ?
Thanks !

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Use this for your field set:

<fieldset autoRun="true" submitButton="false">
  <input type="radio" token="field1">
    <choice value="Serial Number">Serial Number</choice>
    <choice value="Purchase Order">PO</choice>
    <change>
      <condition value="Serial Number">
        <set token="SN">SN</set>
        <unset token="PO" />
        <set token="purchase_order_token">*</set>
      </condition>
      <condition value="Purchase Order">
        <set token="PO">PO</set>
        <unset token="SN" />
        <set token="serial_number_token">*</set>
      </condition>
    </change>
  </input>
   <input type="text" token="serial_number_token" searchWhenChanged="true" depends="$SN$">
     <label>Enter a SN</label>
     <default>*</default>
     <suffix></suffix>
   </input>
   <input type="text" token="purchase_order_token" searchWhenChanged="true" depends="$PO$">
     <label>Enter a Purchase Order</label>
     <default>*</default>
     <suffix></suffix>
   </input>
</fieldset>

This will only show the text field matching the radio selection, and set the other text field back to its asterisk default to make the search work as intended.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Use this for your field set:

<fieldset autoRun="true" submitButton="false">
  <input type="radio" token="field1">
    <choice value="Serial Number">Serial Number</choice>
    <choice value="Purchase Order">PO</choice>
    <change>
      <condition value="Serial Number">
        <set token="SN">SN</set>
        <unset token="PO" />
        <set token="purchase_order_token">*</set>
      </condition>
      <condition value="Purchase Order">
        <set token="PO">PO</set>
        <unset token="SN" />
        <set token="serial_number_token">*</set>
      </condition>
    </change>
  </input>
   <input type="text" token="serial_number_token" searchWhenChanged="true" depends="$SN$">
     <label>Enter a SN</label>
     <default>*</default>
     <suffix></suffix>
   </input>
   <input type="text" token="purchase_order_token" searchWhenChanged="true" depends="$PO$">
     <label>Enter a Purchase Order</label>
     <default>*</default>
     <suffix></suffix>
   </input>
</fieldset>

This will only show the text field matching the radio selection, and set the other text field back to its asterisk default to make the search work as intended.

clairebesson
Explorer

It works perfectly ! thank you very much

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...