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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...