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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...