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!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...