<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I apply JavaScript on a multiselect dropdown menu? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313822#M20115</link>
    <description>&lt;P&gt;@jeffland &lt;BR /&gt;
i am using below on the multiselect but its not working for me.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;input type="multiselect" token="SERVERNAME" id="multi" searchWhenChanged="false"&amp;gt;
        &amp;lt;label&amp;gt;Select &amp;lt;/label&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| inputlookup | sort Servers&amp;lt;/query&amp;gt;
        &amp;lt;/search&amp;gt;
         &amp;lt;fieldForLabel&amp;gt;Servers&amp;lt;/fieldForLabel&amp;gt;
        &amp;lt;fieldForValue&amp;gt;host&amp;lt;/fieldForValue&amp;gt;
        &amp;lt;delimiter&amp;gt;,&amp;lt;/delimiter&amp;gt;
        &amp;lt;choice value="All"&amp;gt;$VAL$&amp;lt;/choice&amp;gt;
      &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Jan 2020 12:10:02 GMT</pubDate>
    <dc:creator>DataOrg</dc:creator>
    <dc:date>2020-01-29T12:10:02Z</dc:date>
    <item>
      <title>How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313816#M20109</link>
      <description>&lt;P&gt;We have a multiselect dropdown with options "All, A , b, c , D"&lt;/P&gt;

&lt;P&gt;Requirement: Whenever user selects "All" , then user cannot select any other option. If user selects anything  else , then he can select multiple things.&lt;/P&gt;

&lt;P&gt;My logic : Create a JavaScript which reads the value selected by the user and then if "All" is selected , then convert multiselect drop down to a normal dropdown . If anything else is selected , then let it be a multiselect dropdown .&lt;/P&gt;

&lt;P&gt;Things I have tried:&lt;BR /&gt;
1) Fetching value from dropdown to JavaScript using "splunkjs/mvc/textinputview" (var token_def = defaultTokenModel.get("token_name");)&lt;BR /&gt;
2) If token_def = "all"  , then render the view to normal dropdown . Else it remains to be multiselect dropdown.&lt;/P&gt;

&lt;P&gt;Second thing I want to try is by using global flag. Setting it to value 1 when "All" is selected and "0" for others , then passing it to HTML.&lt;/P&gt;

&lt;P&gt;Please advise. Please provide me doc related to JavaScript if available since I am new in this.&lt;BR /&gt;
Thanks in Advance!!!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:18:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313816#M20109</guid>
      <dc:creator>ajaylowes</dc:creator>
      <dc:date>2020-09-29T16:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313817#M20110</link>
      <description>&lt;P&gt;Converting the input doesn't sound like a nice UI to me. I would simply replace the value "All" with a more specific one if the user selects it, and replace any specific selection with "All". See this example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form script="multiselectChanges.js"&amp;gt;
  &amp;lt;label&amp;gt;_temp js multiselect one value&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input id="multi" type="multiselect" token="multi"&amp;gt;
      &amp;lt;label&amp;gt;Multi&amp;lt;/label&amp;gt;
      &amp;lt;choice value="All"&amp;gt;All&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="a"&amp;gt;a&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="b"&amp;gt;b&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="c"&amp;gt;c&amp;lt;/choice&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults | eval info="Your selection: $multi$"&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Javascript:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;define([
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function(mvc) {
    // Get multiselect
    var multi = mvc.Components.get("multi");
    // On change, check selection
    multi.on("change", (selectedValues) =&amp;gt; {
        // Check if input has more than one value and if "All" is in it
        var indexOfAll = selectedValues.indexOf("All");
        if (selectedValues.length &amp;gt; 1 &amp;amp;&amp;amp; selectedValues.includes("All")) {
            // If "All" was selected before current (more specific) selection, remove it from list
            if (indexOfAll == 0) {
                selectedValues.splice(indexOfAll, 1);
                multi.val(selectedValues);
            } else {
                // "All" was selected last, clear input and leave only "All" in it
                multi.val("All");
            }
        }
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Oct 2017 10:03:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313817#M20110</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2017-10-17T10:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313818#M20111</link>
      <description>&lt;P&gt;Tried this but i am afraid that it didn't work.&lt;BR /&gt;
I am still able to select all the values at a time&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2017 19:16:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313818#M20111</guid>
      <dc:creator>ajaylowes</dc:creator>
      <dc:date>2017-11-02T19:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313819#M20112</link>
      <description>&lt;P&gt;Of course you can.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Requirement: Whenever user selects "All" , then user cannot select any other option. If user selects anything else , then he can select multiple things.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You're in the "anything else"-branch there. Have you tried selecting "All" after previously selecting a few other items? It removes the other items. And if you select any other item after "All" was selected, "All" disappears again. This basically means you can never select "All" and any other option at the same time, which is a nicer solution than disabling any other selection while "All" is selected (that would require an additional click to first remove "All" from the selection before the user can select a more specific option).&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 07:24:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313819#M20112</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2017-11-06T07:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313820#M20113</link>
      <description>&lt;P&gt;This can be helpful &lt;A href="https://answers.splunk.com/answers/592973/remove-all-from-multiselect-input-in-dashboard.html#comment-592221"&gt;Splunk Answers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 19:18:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313820#M20113</guid>
      <dc:creator>ashish9433</dc:creator>
      <dc:date>2017-11-23T19:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313821#M20114</link>
      <description>&lt;P&gt;Hi , &lt;/P&gt;

&lt;P&gt;I was able to resolve this by taking reference from both answers provided above . Here is the script which worked for me:&lt;BR /&gt;
    require([&lt;BR /&gt;
          'jquery',&lt;BR /&gt;
          'splunkjs/mvc',&lt;BR /&gt;
          'splunkjs/mvc/simplexml/ready!'&lt;BR /&gt;
      ], function($, mvc){&lt;BR /&gt;
              $('#multi').on("change",function(){&lt;BR /&gt;
                      var multi1 = mvc.Components.get("multi");&lt;BR /&gt;
                      var tokens = mvc.Components.getInstance("default");&lt;BR /&gt;
                      var mytoken = tokens.get("multi")&lt;BR /&gt;
                      var indexOfAll = mytoken.indexOf("All");&lt;BR /&gt;
                       if (mytoken.length &amp;gt; 1 &amp;amp;&amp;amp; mytoken.includes("All"))&lt;BR /&gt;
                      {&lt;BR /&gt;
                          // If "All" was selected before current (more specific) selection, remove it from list&lt;BR /&gt;
                          if (indexOfAll == 0) &lt;BR /&gt;
                          {&lt;BR /&gt;
                              var temp = mytoken.split(" ")&lt;BR /&gt;
                              var temp1 = temp[1]&lt;BR /&gt;
                              multi1.val(temp1);&lt;BR /&gt;
                          } else &lt;BR /&gt;
                          {&lt;BR /&gt;
                              // "All" was selected last, clear input and leave only "All" in it&lt;BR /&gt;
                              multi1.val("All");&lt;BR /&gt;
                          }&lt;BR /&gt;
                      }&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  }); 
  });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Dec 2017 09:18:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313821#M20114</guid>
      <dc:creator>ajaylowes</dc:creator>
      <dc:date>2017-12-22T09:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313822#M20115</link>
      <description>&lt;P&gt;@jeffland &lt;BR /&gt;
i am using below on the multiselect but its not working for me.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;input type="multiselect" token="SERVERNAME" id="multi" searchWhenChanged="false"&amp;gt;
        &amp;lt;label&amp;gt;Select &amp;lt;/label&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| inputlookup | sort Servers&amp;lt;/query&amp;gt;
        &amp;lt;/search&amp;gt;
         &amp;lt;fieldForLabel&amp;gt;Servers&amp;lt;/fieldForLabel&amp;gt;
        &amp;lt;fieldForValue&amp;gt;host&amp;lt;/fieldForValue&amp;gt;
        &amp;lt;delimiter&amp;gt;,&amp;lt;/delimiter&amp;gt;
        &amp;lt;choice value="All"&amp;gt;$VAL$&amp;lt;/choice&amp;gt;
      &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 12:10:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313822#M20115</guid>
      <dc:creator>DataOrg</dc:creator>
      <dc:date>2020-01-29T12:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313823#M20116</link>
      <description>&lt;P&gt;I don't know what you're trying to do and how. Please open a new question, and provide more details there.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 18:57:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/313823#M20116</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2020-01-29T18:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I apply JavaScript on a multiselect dropdown menu?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/620576#M50946</link>
      <description>&lt;P&gt;Is there a way to add the java script in xml inline. I am using cloud version and don't have rights to add the script in path.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 12:01:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-apply-JavaScript-on-a-multiselect-dropdown-menu/m-p/620576#M50946</guid>
      <dc:creator>biju_babu</dc:creator>
      <dc:date>2022-11-11T12:01:33Z</dc:date>
    </item>
  </channel>
</rss>

