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
Get Updates on the Splunk Community!

What's New in Splunk Enterprise 9.4: Features to Power Your Digital Resilience

Hey Splunky People! We are excited to share the latest updates in Splunk Enterprise 9.4. In this release we ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...

SignalFlow: What? Why? How?

What is SignalFlow? Splunk Observability Cloud’s analytics engine, SignalFlow, opens up a world of in-depth ...