Dashboards & Visualizations

Custom JavaScript form gets resetted in SimpleXML

npichugin
Path Finder

Hello, everyone!

I'm trying to create a Splunk 6 SimpleXML dashboard with an <html> within a row. This html snippet contains a pretty simple form with a set of checkboxes and a submit button. The form should validate and process checkbox states and send it to an external web service.

I tried to do the following:

  1. Insert a script="myscript.js" parameter into a toplevel <dashboard> tag
  2. In myscript.js, I write:

require(['jquery'], function($) {

... functions ...

$(document).ready(function() {
$('#myform').submit(submit_func)
load_checkbox_states_from_external_source();
});

});

The problem is that checkboxes' states are not always loaded, and submit button is not always able to submit information (clicking on it just doesn't call any function at all). I checked everything - all functions are getting called and working good, but then some mysterious force resets all checkboxes' states and button's handler back to default. Calling these two functions with a 1 second timeout seems to help, but it isn't a nice and reliable solution.

What do you think, splunkers, what should I do here?

P.S. it seems that Advanced XML does not have this issue, but I do want to use Simple XML, because every other dashboard is written in Simple XML and I want to keep look&feel consistent throughout the app.

Tags (2)
0 Karma
1 Solution

nfilippi_splunk
Splunk Employee
Splunk Employee

Try adding "simplexml/ready!".

require([
    'jquery',
    'splunkjs/mvc/simplexml/ready!'
], function($) {
...
}

View solution in original post

0 Karma

nfilippi_splunk
Splunk Employee
Splunk Employee

Try adding "simplexml/ready!".

require([
    'jquery',
    'splunkjs/mvc/simplexml/ready!'
], function($) {
...
}
0 Karma

npichugin
Path Finder

Your tip seems to be a solution, thank you! I tried to reload my page about 10-15 times, and I didn't see a single checkbox getting resetted.

Could you point me to an explanation of "simplexml/ready!" thing, please?

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...