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!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...