Dashboards & Visualizations

How to make two textboxes work with a submit link if either of them is empty or both of them are not empty?

av_
Path Finder

Hi, 

I am facing an issue while implementing two textboxes in splunk dashboard. 

Requirement is to make the submit button work in three scenarios: 

1. Either of the textbox is empty

2. Both the textboxes are not empty

The submit button is not working as expected.

I am attaching the code here. Please have a look and let me know what's going wrong.

 

<row>
<panel>
<title>MAKE THE TEXTBOX WORK</title>
<input type="text" token="text1" searchWhenChanged="true">
<label>TEXTBOX1</label>
<default></default>
<change>
<unset token="isLifeCycleSubmit"></unset>
<set token="submitLifeCycle">true</set>
<unset token="setSubmitLifeCycle"></unset>
<unset token="form.setSubmitLifeCycle"></unset>
</change>
</input>

<input type="text" token="text2" searchWhenChanged="true">
<label>TEXTBOX2</label>
<default></default>
<change>
<unset token="isLifeCycleSubmit"></unset>
<set token="submitLifeCycle">true</set>
<unset token="setSubmitLifeCycle"></unset>
<unset token="form.setSubmitLifeCycle"></unset>
</change>
</input>
<input type="time" token="lifeTime">
<label>Select Time</label>
<default>
<earliest>@d</earliest>
<latest>now</latest>
</default>
<change>
<unset token="isLifeCycleSubmit"></unset>
<set token="submitLifeCycle">true</set>
<unset token="setSubmitLifeCycle"></unset>
<unset token="form.setSubmitLifeCycle"></unset>
</change>
</input>
<input id="submitLifeCycle" type="link" token="submitLifeCycle" searchWhenChanged="true" depends="$submitLifeCycle$">
<label></label>
<choice value="true">Submit</choice>
<change>
<set token="isLifeCycleSubmit">true</set>
<unset token="submitLifeCycle"></unset>
<unset token="form.submitLifeCycle"></unset>
<set token="setSubmitLifeCycle">true</set>
</change>
</input>
<input id="setSubmitLifeCycle" type="link" token="setSubmitLifeCycle" searchWhenChanged="true" depends="$setSubmitLifeCycle$">
<label></label>
<choice value="true">Submit</choice>
</input>
</panel>
</row>

<row>
<panel >
<table>
<title>QUERY</title>
<search>
<query>index=abc sourcetype ...|eval isSubmit=$isLifeCycleSubmit$ </query>

</search>

</table>

Labels (2)
0 Karma

danspav
SplunkTrust
SplunkTrust

Hi @av_,

Here's a solution that doesn't use javascript - just tokens in simplexml.

Each text box is set up like this:

<input type="text" token="text1" searchWhenChanged="true">
        <label>TEXTBOX1</label>
        <default></default>
        <change>
          <condition match="value=&quot;&quot; AND $text2$=&quot;&quot;">
            <unset token="search_can_proceed"></unset>
          </condition>
          <condition match="value=&quot;&quot; AND NOT $text2$=&quot;&quot;">
            <set token="search_can_proceed">true</set>
          </condition>
          <condition match="NOT value=&quot;&quot; AND NOT $text2$=&quot;&quot;">
            <set token="search_can_proceed">true</set>
          </condition>
        </change>
      </input>

 

The tokens are set when the text changes:

  • If both are empty, we unset the search_can_proceed token
  • If one has text but the other is empty then we set the search_can_proceed token

Next, we make the search dependent on that token - and display a helpful panel that tells the user to enter text before the search will run:

<row>
    <panel>
      <table depends="$search_can_proceed$">
        <title>QUERY</title>
        <search depends="$search_can_proceed$">
          <query>|makeresults | eval TEXTBOX1=$text1|s$, TEXTBOX2=$text2|s$ </query>
        </search>
      </table>
      <html rejects="$search_can_proceed$">
        <h1> Please enter a term for TEXTBOX1 And/Or TEXTBOX2.</h1>
      </html>
    </panel>
  </row>

 

The depends and rejects attributes let us show a panel based on the token existing or not.

Here's the dashboard all together:

<form>
  <label>Dueling Text Boxes</label>
  <init>
    <unset token="search_can_proceed"></unset>
  </init>
  <row>
    <panel>
      <title>Please enter a term for TEXTBOX1 And/Or TEXTBOX2</title>
      <input type="text" token="text1" searchWhenChanged="true">
        <label>TEXTBOX1</label>
        <default></default>
        <change>
          <condition match="value=&quot;&quot; AND $text2$=&quot;&quot;">
            <unset token="search_can_proceed"></unset>
          </condition>
          <condition match="value=&quot;&quot; AND NOT $text2$=&quot;&quot;">
            <set token="search_can_proceed">true</set>
          </condition>
          <condition match="NOT value=&quot;&quot; AND NOT $text2$=&quot;&quot;">
            <set token="search_can_proceed">true</set>
          </condition>
        </change>
      </input>
      <input type="text" token="text2" searchWhenChanged="true">
        <label>TEXTBOX2</label>
        <default></default>
        <change>
          <condition match="value=&quot;&quot; AND $text1$=&quot;&quot;">
            <unset token="search_can_proceed"></unset>
          </condition>
          <condition match="value=&quot;&quot; AND NOT $text1$=&quot;&quot;">
            <set token="search_can_proceed">true</set>
          </condition>
          <condition match="NOT value=&quot;&quot; AND NOT $text1$=&quot;&quot;">
            <set token="search_can_proceed">true</set>
          </condition>
        </change>
      </input>
      <input type="time" token="lifeTime">
        <label>Select Time</label>
        <default>
          <earliest>@d</earliest>
          <latest>now</latest>
        </default>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <table depends="$search_can_proceed$">
        <title>QUERY</title>
        <search depends="$search_can_proceed$">
          <query>|makeresults | eval TEXTBOX1=$text1|s$, TEXTBOX2=$text2|s$ </query>
        </search>
      </table>
      <html rejects="$search_can_proceed$">
        <h1> Please enter a term for TEXTBOX1 And/Or TEXTBOX2.</h1>
      </html>
    </panel>
  </row>
</form>

 

The only drawback to this is that if the tokens are set in the URL - e.g. by a drilldown, then the user will need to make the text box content change before the search is run.

 

0 Karma
Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...