Dashboards & Visualizations

Multiselect clear selections

mwdbhyat
Builder

Hi there,

How can I clear all of the selected options in a multiselect with one click? Is there a way to make it "reset" the entire box if I want to?

Thanks!

0 Karma
1 Solution

vnravikumar
Champion

Hi

Try this

<form script="reset.js">
  <label>resetbutton</label>
  <fieldset submitButton="false">
    <input type="multiselect" token="field1">
      <label>field1</label>
      <choice value="one">One</choice>
      <choice value="two">Two</choice>
      <choice value="three">Three</choice>
    </input>
    <html>
      <input type="button" id="reset" value="Reset"/>
    </html>
  </fieldset>
</form>

Javascript:

require([
     'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/simplexml/ready!'
 ], function($, mvc) {
      var tokens = mvc.Components.get("default");
     $("#reset").click(function(){
      tokens.unset("form.field1");
    });

 });

View solution in original post

0 Karma

vnravikumar
Champion

Hi

Try this

<form script="reset.js">
  <label>resetbutton</label>
  <fieldset submitButton="false">
    <input type="multiselect" token="field1">
      <label>field1</label>
      <choice value="one">One</choice>
      <choice value="two">Two</choice>
      <choice value="three">Three</choice>
    </input>
    <html>
      <input type="button" id="reset" value="Reset"/>
    </html>
  </fieldset>
</form>

Javascript:

require([
     'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/simplexml/ready!'
 ], function($, mvc) {
      var tokens = mvc.Components.get("default");
     $("#reset").click(function(){
      tokens.unset("form.field1");
    });

 });
0 Karma

mwdbhyat
Builder

Thanks that works too!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@mwdbhyat

You have to just unset that input.

Like, if XML

<unset token="multiselect_token"></unset>

Ref: https://conf.splunk.com/files/2017/slides/tokens-in-splunk-web-framework-use-abuse-and-incantations....

Using Javascript:

 var defaultTokenModelun = mvc.Components.getInstance('default', {create: true});
 var submittedTokenModelun = mvc.Components.getInstance('submitted', {create: true});

 function unsetToken(name) {
     defaultTokenModelun.unset(name);
     submittedTokenModelun.unset(name);
 }

 $(document).on("click", "#ButtonId", function() {
         unsetToken("multiselect_token")
 });

mwdbhyat
Builder

Thanks both worked!

0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...