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>
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="" AND $text2$=""">
<unset token="search_can_proceed"></unset>
</condition>
<condition match="value="" AND NOT $text2$=""">
<set token="search_can_proceed">true</set>
</condition>
<condition match="NOT value="" AND NOT $text2$=""">
<set token="search_can_proceed">true</set>
</condition>
</change>
</input>
The tokens are set when the text changes:
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="" AND $text2$=""">
<unset token="search_can_proceed"></unset>
</condition>
<condition match="value="" AND NOT $text2$=""">
<set token="search_can_proceed">true</set>
</condition>
<condition match="NOT value="" AND NOT $text2$=""">
<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="" AND $text1$=""">
<unset token="search_can_proceed"></unset>
</condition>
<condition match="value="" AND NOT $text1$=""">
<set token="search_can_proceed">true</set>
</condition>
<condition match="NOT value="" AND NOT $text1$=""">
<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.