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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

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

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...