Dashboards & Visualizations

Why do I have to reload my dashboard to execute a search?

JarrenJ
Explorer

I am using Javascript to dynamically add a hash string to an input from splunk, based on its ID. it updates the value of the input but when i click Submit, it doesnt do anything. I have to refresh the page and then paste in the value for it to work. This defeats the purpose of autofilling the input field based on the file uploaded.

any help would appreciated, thanks!

EDIT:

This is my script:

$(document).ready(function () {
  $("#btn").click(function () {
      var reader = new FileReader(); //define a Reader
      var file = $("#f1")[0].files[0]; //get the File object 
      if (!file) {
          alert("no file selected");
          return;
      } //check if user selected a file

      reader.onload = function (f) {
          var file_result = this.result; // this == reader, get the loaded file "result"
          var file_wordArr = CryptoJS.lib.WordArray.create(file_result); //convert blob to WordArray
          var sha1_hash = CryptoJS.SHA1(file_wordArr); //calculate SHA1 hash
            $('#input1_3520-input').attr('value', sha1_hash);
          //document.getElementById("input1_3520-input").value = sha1_hash; //put hash into input field
          //alert("Calculated SHA1:" + sha1_hash.toString()); //output result
      };
      reader.readAsArrayBuffer(file); //read file as ArrayBuffer
  });
});

It works, it puts the generated hash into my field but to actually run the search, I need to copy the hash, reload the page and then paste it in and it works... I don't think its a timing issue. Could it be that it is only changing the text value of the input field and not that actual value?

EDIT #2:

Now, I don't need to reload the page i just need to actually type a character in the field, hit submit, then delete the added character and hit submit again and it runs the search on the hash... My only guess is that the input field isn't actually detected a value change?

0 Karma

elliotproebstel
Champion

I've seen behavior like this when my javascript had some timing issues. Can you share the dashboard XML and javascript code? Feel free to obfuscate any sensitive data.

0 Karma

JarrenJ
Explorer

thanks for the response guys, see the updated question.

0 Karma
Get Updates on the Splunk Community!

Demo Day: Strengthen Your SOC with Splunk Enterprise Security 8.1

Today’s threat landscape is more complex than ever. Security operation centers (SOCs) are overwhelmed with ...

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...