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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...