Dashboards & Visualizations

How to use a checkbox to hide a text box?

sjones
Engager

I'd like to have a checkbox, which when checked will either show or enable a text field, and when unchecked will hide or disable the text field:

 

 

<input type="checkbox" token="reqIdFilter">
<label></label>
<choice value="Enable">Enable</choice>
<change>
<condition match="$reqIdFilter$==&quot;Enable&quot;">
<set token="showReqIdFilter">Y</set>
</condition>
<condition>
<unset token="showReqIdFilter"></unset>
</condition>
</change>
</input>
<input type="text" token="RequestId" depends="$showReqIdFilter$">
<label>RequestId</label>
</input>

 

 

But that doesn't seem to work. Is there something wrong with the above?

Second, I'd like the search to use the value of $RequestId$ only if the checkbox is checked, how can I do that?

`mySearch $RequestId$` will always inject $RequestId$, how can i make this conditional on the checkbox?

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

The easiest way to set/unset "options" using checkbox is by using a single eval statement to set/unset the token - note searchWhenChanged=true.

      <input type="checkbox" token="reqIdFilter" searchWhenChanged="true">
        <label></label>
        <choice value="enable_id_filter">Enable</choice>
        <change>
          <eval token="showReqIdFilter">if(match($reqIdFilter$, "enable_id_filter"), "true", null())</eval>
          <set token="form.RequestId"></set>
        </change>
      </input>
      <input type="text" token="RequestId" depends="$showReqIdFilter$">
        <label>RequestId</label>
      </input>

This also clears the RequestId token if you toggle the Enable checkbox. In your search just leave the $RequestId$ in there. It will be cleared when you click the box so will just be an empty string

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The easiest way to set/unset "options" using checkbox is by using a single eval statement to set/unset the token - note searchWhenChanged=true.

      <input type="checkbox" token="reqIdFilter" searchWhenChanged="true">
        <label></label>
        <choice value="enable_id_filter">Enable</choice>
        <change>
          <eval token="showReqIdFilter">if(match($reqIdFilter$, "enable_id_filter"), "true", null())</eval>
          <set token="form.RequestId"></set>
        </change>
      </input>
      <input type="text" token="RequestId" depends="$showReqIdFilter$">
        <label>RequestId</label>
      </input>

This also clears the RequestId token if you toggle the Enable checkbox. In your search just leave the $RequestId$ in there. It will be cleared when you click the box so will just be an empty string

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...