All Apps and Add-ons

How to preserve template in checkboxes module and set checkboxes checked by default

royimad
Builder

I need to draw and populate a list of checkboxes dynamically from a search using sideview.
The following code will fill those checkboxes, what i need is that those checkboxes are checked by default and to preserve all the values in "test2" parameter ( all the selected values )

The code is the above:

<view autoCancelInterval="90" isVisible="True" onunloadCancelJobs="true" template="dashboard.html" isSticky="False">
  <label>Uptime Explorer</label>
  <module name="AccountBar" layoutPanel="appHeader" />
  <module name="AppBar" layoutPanel="appHeader" />
  <module name="SideviewUtils" layoutPanel="appHeader" />


  <module name="Message" layoutPanel="messaging">
    <param name="filter">*</param>
    <param name="maxSize">2</param>
    <param name="clearOnJobDispatch">False</param>
  </module>


  <module name="HTML" layoutPanel="viewHeader">
    <param name="html"><![CDATA[
    <h1>Uptime Explorer</h1>
    ]]></param>
  </module>


  <module name="URLLoader" layoutPanel="panel_row1_col1" autoRun="True">
    <param name="keepURLUpdated">True</param>

      <module name="TimeRangePicker" layoutpanel="panel_row2_col2" group="Second Group">
        <param name="default">Last 15 minutes</param>

        <module name="Search" layoutPanel="panel_row2_col1" group="Select a Series and a Locations" autoRun="true">
          <param name="search"><![CDATA[
           |savedsearch Devices_Locations | eval DeviceId=DeviceId | stats values(Location) as name  | fields - count | mvexpand name | eval value=name | fields - name
          ]]></param>



          <module name="Checkboxes">
            <param name="name">test2</param>
            <param name="valueField">value</param>
            <param name="labelField">label</param>
            <param name="separator">+OR+</param> 
            <param name="template">Location="$value$"</param>
            <param name="outerTemplate">( $value$ )</param>

            <module name="Button" layoutpanel="panel_row2_col2" group="Second Group">

              <module name="Search" layoutPanel="panel_row2_col2" group="Second Group" autoRun="False" >
                <param name="search" autoRun="False"><![CDATA[
                  |savedsearch Devices_Locations | where $test2$ | stats values(DeviceId) as DeviceId  | fields DeviceId  ]]>      
                </param>

                <module name="Table">
                  <param name="count">1000</param>
                </module>
              </module>
            </module>   
          </module>   
        </module>
      </module>
    </module>

</view>
1 Solution

sideview
SplunkTrust
SplunkTrust

It's no problem. It works just like the Pulldown module as far as how you prepopulate the selections - you use a ValueSetter.

As far as having the users selection remain selected, the URLLoader will keep them selected so if they use the back button to return to the page, or if they reload the page in their browser, it'll still be in the state it was when they left the page. As far as remembering selection state across selections, we don't have a way to do that yet, but it's not as commonly asked for so hopefully you're not asking about that.

So put this ValueSetter upstream from the Pulldown and downstream from the URLLoader.

<module name="ValueSetter">
  <param name="name">test2</param>
  <param name="value">fooValue,barValue</param>
  <param name="delim">,</param>
  <param name="allowClobber">False</param>

It says to select the "fooValue" and "barValue" checkboxes. It also sets allowClobber to false, which will mean in this case, if the URLLoader has already set it from upstream, the URLLoader is boss and the ValueSetter will do nothing. Since keepUrlUpdated is set to True, this in turn means the URLLoader will set the value in the URL as soon as the Checkboxes are interacted with, so in practice the ValueSetter will only set the default the first time the page loads.

You can read more about ValueSetter's uses, including all these less commonly used params delim and allowClobber, in the ValueSetter docs page in Sideview Utils itself. The Pulldown may need a cross reference to the ValueSetter page for the prepopulation question and assuming that's not there already I'll add it to the docs for the next release.

View solution in original post

sideview
SplunkTrust
SplunkTrust

WARNING: Roy you should take all those extra autoRun attributes out of this view. Those can cause havoc. take all of them out except the autoRun="True" on the URLLoader. The autoRun="False" attributes are completely meaningless and should always be removed when you see them. They are evil because someone else will see them and think they mean something.

And putting autoRun="True" on a module that is nested inside another module that already has an autoRun="True" is redundant, but in a very dangerous way in that it also causes very strange things to happen.

0 Karma

sideview
SplunkTrust
SplunkTrust

It's no problem. It works just like the Pulldown module as far as how you prepopulate the selections - you use a ValueSetter.

As far as having the users selection remain selected, the URLLoader will keep them selected so if they use the back button to return to the page, or if they reload the page in their browser, it'll still be in the state it was when they left the page. As far as remembering selection state across selections, we don't have a way to do that yet, but it's not as commonly asked for so hopefully you're not asking about that.

So put this ValueSetter upstream from the Pulldown and downstream from the URLLoader.

<module name="ValueSetter">
  <param name="name">test2</param>
  <param name="value">fooValue,barValue</param>
  <param name="delim">,</param>
  <param name="allowClobber">False</param>

It says to select the "fooValue" and "barValue" checkboxes. It also sets allowClobber to false, which will mean in this case, if the URLLoader has already set it from upstream, the URLLoader is boss and the ValueSetter will do nothing. Since keepUrlUpdated is set to True, this in turn means the URLLoader will set the value in the URL as soon as the Checkboxes are interacted with, so in practice the ValueSetter will only set the default the first time the page loads.

You can read more about ValueSetter's uses, including all these less commonly used params delim and allowClobber, in the ValueSetter docs page in Sideview Utils itself. The Pulldown may need a cross reference to the ValueSetter page for the prepopulation question and assuming that's not there already I'll add it to the docs for the next release.

royimad
Builder

can ValueSetter could be populated with the same search as the checkboxes module? so i will use value inside a value setter instead of listing all the values one by one?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...