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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...