Dashboards & Visualizations

Reading a text token with javascript.

mike-48735
Engager

I am starting to add some JS elements to dashboards.  I can't quite get the text input box to work like I think it should be. (nor is the time range working, but I hadn't worked on that really). I feel like I am close but I have tried a few options and it isn't loading.

 

<form script="js/views/js_testing.js">
  <label>JS Testing</label>
  <fieldset submitButton="true">
    <input type="text" token="ip_field1">
      <label>Test Value</label>
    </input>
    <input type="time" token="field1">
      <label>Time Picker</label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Test data - $ip_field1$</title>
      <html>
        <div id="mytable1"/>
      </html>
    </panel>
  </row>
</form>

 

 

Javascript&colon;

 

// LIBRARIES

require([
    "splunkjs/mvc",
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/singleview",
    "splunkjs/mvc/tableview",
    "splunkjs/mvc/simplexml/ready!"
], function(
    mvc,
    SearchManager,
    SingleView,
    TableView
) {

 // SEARCH MANAGERS
    var search1 = new SearchManager({
        id: "connections",
        search: "index=zeek_conn id.orig_h=$ip_field1$ OR id.resp_h=$ip_field1$ | table _time id.orig_h id.resp_h",
        preview: true,
        cache: true,
        earliest_time: "-30d",
        latest_time: "now"
    }, {tokens: true});

// TOKENS
    var tokens = mvc.Components.get("default");
    $(document).on("click", "#submit", function(e){
        var tok1 = tokens.get("ip_field1");

        if (tok1 == undefined || tok1 == ""){
            tokens.set("ip_field1", "*");
        }
    });
    
    var mytoken = tokens.get("ip_field1");

// INSERT_TABLE_VIEW
    var table1 = new TableView({
        id: "my-table1",
        managerid: "connections",
        el: $("#mytable1")
    }).render();

});

 

 

Thanks!

Labels (1)
0 Karma
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...