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!

Splunk Training for All: Meet Aspiring Cybersecurity Analyst, Marc Alicea

Splunk Education believes in the value of training and certification in today’s rapidly-changing data-driven ...

Investigate Security and Threat Detection with VirusTotal and Splunk Integration

As security threats and their complexities surge, security analysts deal with increased challenges and ...

Observability Highlights | January 2023 Newsletter

 January 2023New Product Releases Splunk Network Explorer for Infrastructure MonitoringSplunk unveils Network ...