Dashboards & Visualizations

How can I have a checkbox checked by default?

monteiroh
Explorer

Hi
I want to have a checkbox that is checked by default and when unchecked I do not want it to have value="undefined", I want empty value equal to " ". Seems like on the token $value$ is still empty when checked.

Thanks in advance.

Tags (2)
0 Karma
1 Solution

kmaron
Motivator

I think I figured it out but it's a bit messy. Hopefully this will work or someone else will have a different idea.

<form>
  <label>dashbaord label</label>
  <init>
     <set token="field1">Data1</set>
   </init>
  <fieldset submitButton="false">
    <input type="checkbox" token="field1">
      <label>field1</label>
      <choice value="Data1">Data1</choice>
      <choice value="Data2">Data2</choice>
      <default>Data1</default>
      <change>
        <eval token="field1">if(isnull($field1$), &quot; &quot;, $field1$)</eval>
      </change>
      <initialValue>Data1</initialValue>
      <delimiter> </delimiter>
    </input>
  </fieldset>

Okay so basically initialize the token (field1) at the top to the default vaule
Set the default and initial value in the definition of the checkbox (Data1)
Then the eval looks for the undefined (null) case when the box is unchecked.

View solution in original post

0 Karma

shandr
Path Finder

Try below. Seems simpler. No need for OP's  eval  technique.

Had to use initialValue and not default.

<input type="checkbox" token="showhide_choice_tok" searchWhenChanged="true">
  <label></label>
  <choice value="yes">I want panels</choice>
  <change>
    <condition value="yes">
      <set token="show_panels_tok">show</set>
    </condition>
    <condition>
      <unset token="show_panels_tok"></unset>
    </condition>
  </change>
  <delimiter> </delimiter>
  <initialValue>yes</initialValue>
</input>

0 Karma

kmaron
Motivator

I think I figured it out but it's a bit messy. Hopefully this will work or someone else will have a different idea.

<form>
  <label>dashbaord label</label>
  <init>
     <set token="field1">Data1</set>
   </init>
  <fieldset submitButton="false">
    <input type="checkbox" token="field1">
      <label>field1</label>
      <choice value="Data1">Data1</choice>
      <choice value="Data2">Data2</choice>
      <default>Data1</default>
      <change>
        <eval token="field1">if(isnull($field1$), &quot; &quot;, $field1$)</eval>
      </change>
      <initialValue>Data1</initialValue>
      <delimiter> </delimiter>
    </input>
  </fieldset>

Okay so basically initialize the token (field1) at the top to the default vaule
Set the default and initial value in the definition of the checkbox (Data1)
Then the eval looks for the undefined (null) case when the box is unchecked.

0 Karma
Get Updates on the Splunk Community!

Splunk Lantern | Getting Started with Edge Processor, Machine Learning Toolkit ...

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

Enterprise Security Content Update (ESCU) | New Releases

In the last month, the Splunk Threat Research Team (STRT) has had 2 releases of new security content via the ...

Announcing the 1st Round Champion’s Tribute Winners of the Great Resilience Quest

We are happy to announce the 20 lucky questers who are selected to be the first round of Champion's Tribute ...