Dashboards & Visualizations

How to reset tokens upon clicking submit button

twishtrisha
Loves-to-Learn Lots

I'm having trouble with my code. My goal is when I click A in the radio button, it would show up a list of values under A and there's a checkbox per row...Upon clicking a checkbox, it should show on Panel B. (I have that one sorted out)

 

My problem is, when I pick B in the radio button, and a list shows up in the Details panel, everything I clicked on A and B will show up. I only need B to show up. I need help to reset whenever I click a new radio button and hit submit. I don't know where to reset it though. Thank you in advance!

 

twishtrisha_1-1595944110219.png

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function (_, $, mvc, TableView) {
    // Access the "default" token model
    var tokens = mvc.Components.get("default");
    var selected_values_array = [];
    var submittedTokens = mvc.Components.get('submitted');
    console.log("This is Multi-select table JS");
    // Custom renderer for applying checkbox.
    var CustomRenderer = TableView.BaseCellRenderer.extend({
        canRender: function (cell) {
            return _(['Select server']).contains(cell.field);
        },
        render: function ($td, cell) {
            var a = $('<div>').attr({
                "id": "chk-server" + cell.value,
                "value": cell.value
            }).addClass('checkbox').click(function () {
                if ($(this).attr('class') === "checkbox") {
                    selected_values_array.push($(this).attr('value'));
                    $(this).removeClass();
                    $(this).addClass("checkbox checked");
                } else {
                    $(this).removeClass();
                    $(this).addClass("checkbox");
                    var i = selected_values_array.indexOf($(this).attr('value'));
                    if (i != -1) {
                        selected_values_array.splice(i, 1);
                    }
                }
                console.log(selected_values_array);
            }).appendTo($td);
        }
    });

    //List of table ID
    var sh = mvc.Components.get("myTable");
    if (typeof (sh) != "undefined") {
        sh.getVisualization(function (tableView) {
            // Add custom cell renderer and force re-render
            tableView.table.addCellRenderer(new CustomRenderer());
            tableView.table.render();
        });
    }

    $(document).ready(function () {

        //setting up tokens with selected value.
        $("#mybutton").on("click", function (e) {
            e.preventDefault();
            tokens.set("mytoken", selected_values_array.join());
            submittedTokens.set(tokens.toJSON());
        });

    });
});
Labels (3)
0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...