Dashboards & Visualizations
Highlighted

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

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
Highlighted

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

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

Highlighted

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

Explorer

It works perfectly ! thank you very much

0 Karma