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!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...