Dashboards & Visualizations

Submit button per panel in Simple XML

chris
Motivator

Ist it possible to have one submit button per panel in a simple XML dashboard/form? I saw that it is not possible to have a <fieldset> element as a child of a <pane>. Am I doing something wrong?

Regards
Chris

Tags (3)
1 Solution

rjthibod
Champion

As @somesoni2 said, SimpleXML does not allow more than the one Submit button, the one on the top of a dashboard. You can work around this with Advanced XML (per the other link @digitalX shared), but Advanced XML is deprecated in Splunk 6.x.

I worked around this issue with some JavaScript extensions to my SimpleXML. I have shared the code and more details on my blog post here: https://blog.octoinsight.com/there-can-be-only-one-submit-button

The function in the post allows you to specify the panel name and how you want the button to appear. The gist of the code is below.

      // generate html button in parent element
      // id: id and name to use on the html button
      // label: label/span to apply to the button
      // parent: id of parent html element in which to place the button
      // append?: should append or prepend in parent list of children
      // submit?: should it be a submit button type or not
      // vertical?: is the button used in a vertical list of items
      generateButton = function(id, label, parent, append, submit, vertical) {

        var btn = document.createElement('button');
        var span;

        // apply id field
        if (typeof id !== 'undefined' && id.length > 0) {
          btn.id = id;
          btn.name = id;
        }

        // apply label
        if (typeof label !== 'undefined' && label.length > 0) {
          span = document.createElement('span');
          span.innerHTML = label;
          btn.appendChild(span);
        }

        // assign styling and insert if parent is set
        if (typeof parent !== 'undefined' && parent.length > 0) {
          var parentID = (parent[0] === '#' ? parent : '#' + parent);
          var p = $(parentID);

          if (p.length) {

            // set button in its place of the parent
            var t = p.find('.fieldset');
            if (t.length) {
              t = $(t[0]);
              if (!!append) {
                t.append(btn);
              } else {
                t.prepend(btn);
              }
            }
          }
        }

        // set button type classes and CSS
        if (!!submit) {
          btn.className = 'btn btn-primary';
        } else {
          btn.className = 'btn-info';
          btn.style.padding = "3px 12px";
          btn.style.borderRadius = "4px";
        }

        // set button CSS based on it being in a
        // vertical stack of items or not
        if (!!vertical) {
          btn.style.verticalAlign = 'middle';
          btn.style.margin = "5px 10px 5px 0px";
        } else {
          btn.style.verticalAlign = 'top';
          btn.style.marginTop = "21px";
          btn.style.marginRight = " 10px";
        }

        return $(btn);
      };

View solution in original post

woodcock
Esteemed Legend

The simpleXML submit button is horribly broken and for complex usecases, cannot be made to work.  Try this dahsboard's no-JavaScript approach instead:

 

<form theme="dark">
  <label>PoC demonstrating a fully-functioning no-JS SUBMIT "button" (actually "checkbox").</label>
  <description>https://community.splunk.com/t5/Dashboards-Visualizations/SimpleXML-Inherent-brokenness-regarding-autorun-and-Submit/m-p/407351  For intricate technical reasons that Splunk considers "working as intended", the "real" SUBMIT button is fundamentally broken and CANNOT BE MADE TO WORK for many usecases (i.e. when you must use "true" for "searchWhenChanged").  Fortunately, the method demonstrated herein does everything that anyone could desire with only 1 downside which is this: there is no way to make the dashboard autorun on first load (not even if you click the CHECKBOX with a URI in the URL).  Notice that even though some of the controls interact with one-another, the actual search does not run until the SUBMIT box is checked.  Here are the pieces that are required. 1: DO NOT CHANGE ANYTHING ABOUT THE "SUBMIT" checkbox other than cosmetic things (e.g. html).  2: Ensure that EVERY OTHER CONTROL has a "&lt;change&gt;...&lt;/change&gt;" section that unsets BOTH these tokens: {"SUBMIT_CHECKBOX", "form.SUBMIT_CHECKBOX"}.  3: Ensure that 1 search in every chain of searches uses the do-nothing "$SUBMIT_CHECKBOX$" token somewhere (i.e. if all searches are driven by a base search, this only has to be done in the base search, not the post-process searches).  This token will always be either unset or blank so it does not matter where you put it.  4: Neither the individual "searchWhenChanged" values of the controls NOR the global "Autorun dashboard" value makes any difference.  For support contact woodcock@splunxter.com.</description>
  <fieldset submitButton="false" autoRun="true">
    <input type="multiselect" token="INDEX" searchWhenChanged="true">
      <label>Select Index value(s)</label>
      <fieldForLabel>label</fieldForLabel>
      <fieldForValue>value</fieldForValue>
      <default>*</default>
      <search>
        <query>|tstats count dc(host) WHERE index=* AND $SOURCETYPE$ BY index
| rename index AS value
| eval label = value
| append [|makeresults | eval label = "All", value="*"]
| table label value</query>
        <earliest>$timepicker.earliest$</earliest>
        <latest>$timepicker.latest$</latest>
      </search>
      <delimiter> OR index=</delimiter>
      <valuePrefix>"</valuePrefix>
      <valueSuffix>"</valueSuffix>
      <prefix>(index=</prefix>
      <change>
        <eval token="form.INDEX">case(mvcount($form.INDEX$) == 2 AND mvindex($form.INDEX$, 0) == "*", mvindex($form.INDEX$, 1), mvfind($form.INDEX$, "^[*]") == mvcount($form.INDEX$) - 1, "*", true(), $form.INDEX$)</eval>
        <unset token="SUBMIT_CHECKBOX"></unset>
        <unset token="form.SUBMIT_CHECKBOX"></unset>
      </change>
      <suffix>)</suffix>
    </input>
    <input type="multiselect" token="SOURCETYPE" searchWhenChanged="true">
      <label>Select sourcetype value(s)</label>
      <fieldForLabel>label</fieldForLabel>
      <fieldForValue>value</fieldForValue>
      <default>*</default>
      <search>
        <query>|tstats count dc(host) WHERE $INDEX$ AND sourcetype=* BY sourcetype
| rename sourcetype AS value
| eval label = value
| append [|makeresults | eval label = "All", value="*"] 
| table label value</query>
        <earliest>$timepicker.earliest$</earliest>
        <latest>$timepicker.latest$</latest>
      </search>
      <delimiter> OR sourcetype=</delimiter>
      <valuePrefix>"</valuePrefix>
      <valueSuffix>"</valueSuffix>
      <prefix>(sourcetype=</prefix>
      <change>
        <eval token="form.SOURCETYPE">case(mvcount($form.SOURCETYPE$) == 2 AND mvindex($form.SOURCETYPE$, 0) == "*", mvindex($form.SOURCETYPE$, 1), mvfind($form.SOURCETYPE$, "^[*]") == mvcount($form.SOURCETYPE$) - 1, "*", true(), $form.SOURCETYPE$)</eval>
        <unset token="SUBMIT_CHECKBOX"></unset>
        <unset token="form.SUBMIT_CHECKBOX"></unset>
      </change>
      <suffix>)</suffix>
    </input>
    <input type="text" token="COUNT">
      <label>Name for "count" field</label>
      <default>count</default>
      <change>
        <unset token="SUBMIT_CHECKBOX"></unset>
        <unset token="form.SUBMIT_CHECKBOX"></unset>
      </change>
    </input>
    <input type="time" token="timepicker" searchWhenChanged="true">
      <label>Timepicker</label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
      <change>
        <unset token="SUBMIT_CHECKBOX"></unset>
        <unset token="form.SUBMIT_CHECKBOX"></unset>
      </change>
    </input>
    <input id="submit_checkbox" type="checkbox" token="SUBMIT_CHECKBOX">
      <label></label>
      <delimiter> </delimiter>
      <choice value="">SUBMIT</choice>
    </input>
    <html depends="$hide$">
      <style>
        #submit_checkbox{
          width:80px !important;
        }
        #submit_checkbox
div[data-component="splunk-core:/splunkjs/mvc/components/LinkList"]{
          width:80px !important;
        }
        #submit_checkbox  button{
          padding: 6px 15px !important;
          border-radius: 3px !important;
          font-weight: 500 !important;
          background-color: #5cc05c !important;
          border: transparent !important;
          color: #fff !important
        }
        #submit_checkbox  button:hover{
          background-color: #40a540 !important;
          border-color: transparent !important;
        }
    </style>
  </html>
  </fieldset>
  <row>
    <panel>
      <table>
        <title>Searches ONLY on checking the SUBMIT box (which resets itself)</title>
        <search>
          <query>|tstats count AS $COUNT|s$ dc(host) WHERE $INDEX$ AND $SOURCETYPE$ BY index sourcetype $SUBMIT_CHECKBOX$</query>
          <earliest>$timepicker.earliest$</earliest>
          <latest>$timepicker.latest$</latest>
        </search>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>

 

0 Karma

helge
Builder

It would be nice if it were possible to have multiple submit buttons per page in Simple XML.
Here is my scenario:
Global fieldset with filters for all charts and tables on the dashboard. Several of those charts and tables have additional filtering options, i.e. multiple input controls. Sometimes it only makes sense to rerun a panel's search when all its input controls have been configured by the user. This is especially true if the search is "expensive" and runs for a long time.

rjthibod
Champion

This is exactly the problem that made me get motivated to come up with my JS solution posted down below. @helge, you are more than welcome to take my code from our app. It is tested and certified for 6.x.

rjthibod
Champion

Also note there was a bug in 6.5.0 and 6.5.1 where the searchWhenChanged=false setting was ignored for input elements inside of panels. This rendered the cool submit buttons inside of a panel useless because the search were automatically running. Splunk fixed this bug in 6.5.2. My suggestion is you do not test core functionality of buttons on 6.5.0 or 6.5.1 so you don't run around in circles with this issue.

rjthibod
Champion

As @somesoni2 said, SimpleXML does not allow more than the one Submit button, the one on the top of a dashboard. You can work around this with Advanced XML (per the other link @digitalX shared), but Advanced XML is deprecated in Splunk 6.x.

I worked around this issue with some JavaScript extensions to my SimpleXML. I have shared the code and more details on my blog post here: https://blog.octoinsight.com/there-can-be-only-one-submit-button

The function in the post allows you to specify the panel name and how you want the button to appear. The gist of the code is below.

      // generate html button in parent element
      // id: id and name to use on the html button
      // label: label/span to apply to the button
      // parent: id of parent html element in which to place the button
      // append?: should append or prepend in parent list of children
      // submit?: should it be a submit button type or not
      // vertical?: is the button used in a vertical list of items
      generateButton = function(id, label, parent, append, submit, vertical) {

        var btn = document.createElement('button');
        var span;

        // apply id field
        if (typeof id !== 'undefined' && id.length > 0) {
          btn.id = id;
          btn.name = id;
        }

        // apply label
        if (typeof label !== 'undefined' && label.length > 0) {
          span = document.createElement('span');
          span.innerHTML = label;
          btn.appendChild(span);
        }

        // assign styling and insert if parent is set
        if (typeof parent !== 'undefined' && parent.length > 0) {
          var parentID = (parent[0] === '#' ? parent : '#' + parent);
          var p = $(parentID);

          if (p.length) {

            // set button in its place of the parent
            var t = p.find('.fieldset');
            if (t.length) {
              t = $(t[0]);
              if (!!append) {
                t.append(btn);
              } else {
                t.prepend(btn);
              }
            }
          }
        }

        // set button type classes and CSS
        if (!!submit) {
          btn.className = 'btn btn-primary';
        } else {
          btn.className = 'btn-info';
          btn.style.padding = "3px 12px";
          btn.style.borderRadius = "4px";
        }

        // set button CSS based on it being in a
        // vertical stack of items or not
        if (!!vertical) {
          btn.style.verticalAlign = 'middle';
          btn.style.margin = "5px 10px 5px 0px";
        } else {
          btn.style.verticalAlign = 'top';
          btn.style.marginTop = "21px";
          btn.style.marginRight = " 10px";
        }

        return $(btn);
      };

jiaqya
Builder

Im facing similar issue and added the above js , but have not got any idea how to add it to a splunk panel . would also like to enable drill down on the custom button...

0 Karma

somesoni2
Revered Legend

That is correct, you can't have a submit button inside a panel in simple xml. But you can have form inputs, so as a dirty workaround, you can configure your dashboard panels have a checkbox and use the checkbox token in your panel search. Users can uncheck/check the checkbox to re-run the search. Again, can't say enough it's a dirty work around

skoelpin
SplunkTrust
SplunkTrust

Out of curiosity, why have a local submit button for each panel rather than having 1 global submit button?

0 Karma

digitalX
Explorer

have the same Problem. Have seen this Topic:
https://answers.splunk.com/answers/150393/form-input-add-submit-button-for-each-panel.html
But it looks a little complicated with the modules. I hope there is a simpler way to do this...

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...