Dashboards & Visualizations

How do you clear the token values in HTML dashboards?

thisissplunk
Builder

I've got a dashboard that is POSTing stuff to a kv store. It currently clears the input forms once I hit submit, but the actual values seem to still be held in the tokens. For instance, I can hit submit five times in a row, even though the input forms have been cleared, but it will post the same values five times in a row instead one set of values and four blanks.

So yeah, how do I clear these token values?

Here is my html:

var submit = new SubmitButton({
    id: 'submit',
    el: $('#search_btn'),
    text: 'Add to kv store'
}, {tokens: true}).render();

submit.on("submit", function() {
    submitTokens();

    // Below this point is from custom dashboard tutorial
    // When the Submit button is clicked, get all the form fields by accessing token values from their Label field
    var tokens = mvc.Components.get("default");
    var form_ticket = tokens.get("form.ticket");
    var form_type = tokens.get("form.type");
    var form_value = tokens.get("form.value");

    // Create a dictionary to store the field names and values
    var record = { 
        "ticket": form_ticket, 
        "type": form_type, 
        "value": form_value
    }; 

    // Use the request method to send a REST POST request
    // to the storage/collections/data/{collection}/ endpoint
    service.request(
        "storage/collections/data/mykvstore/",
        "POST",
        null,
        null,
        JSON.stringify(record),
        {"Content-Type": "application/json"},
        null)
            .done(function() { 
                 // Run the search again to update the table
                search1.startSearch();

                // Clear the form fields 
                $("#formaddtokvstore input[type=text]").val(""); 
            });
});

To me it looks like it should be re .getting the variables each time which should be blank, but this is not what is happening. Should I just set my variables to empty at the end?

0 Karma
1 Solution

thisissplunk
Builder

Don't know why I forgot this is js. I just reset the tokens at the bottom of the code like this:

tokens.set("for.ticket", "");
tokens.set("form.type", "");
tokens.set("form.value", "");

View solution in original post

0 Karma

thisissplunk
Builder

Don't know why I forgot this is js. I just reset the tokens at the bottom of the code like this:

tokens.set("for.ticket", "");
tokens.set("form.type", "");
tokens.set("form.value", "");
0 Karma

sdawsonkg
Path Finder

@thisissplunk,
I tried the same approach but it is not working for me. Can you please post the whole code ?

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!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...