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!

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...