<?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: Why are tokens set by a javascript file not working correctly when I load a dashboard? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478842#M31404</link>
    <description>&lt;P&gt;@roelscholte I tried doing this but it does not add the label.  Instead, the input field just displays the name of the token in place of the label.  Btw, I removed the &lt;CODE&gt;&amp;lt;label&amp;gt;&lt;/CODE&gt; tag completely from the dashboard XML assuming that the javascript would add it.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2020 15:42:26 GMT</pubDate>
    <dc:creator>andrewtrobec</dc:creator>
    <dc:date>2020-01-03T15:42:26Z</dc:date>
    <item>
      <title>Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478839#M31401</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am currently trying to use javascript governed tokens to manage labels on a dashboard.  For now values are hardcoded within the javascript file.  Here is a simplified version that sets a label &lt;CODE&gt;Company&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function ($, mvc) {
    var def_tok = mvc.Components.get("default");
    var sub_tok = mvc.Components.get("submitted");

    def_tok.set("lbl_company","Company");
    sub_tok.set("lbl_company","Company");
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This script &lt;CODE&gt;loadLabels.js&lt;/CODE&gt; is set to run when the dashboard is loaded, and the label name is used for a dashboard input:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form script="loadLabels.js"&amp;gt;
    ...
    &amp;lt;input type="multiselect" token="tok_company"&amp;gt;
        &amp;lt;label&amp;gt;$lbl_company$&amp;lt;/label&amp;gt;
        ...
    &amp;lt;/input&amp;gt;
    ...
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The javscript file seems to load correctly but the only issue is that the inputs seem to load before the labels, so the result is a dashboard with label-less inputs.  If I click the &lt;CODE&gt;Edit&lt;/CODE&gt; button on the dashboard the label loads and I can &lt;CODE&gt;Cancel&lt;/CODE&gt; out of edit mode and continue to use it until I refresh the dashboard, but obviously this is not a definitive solution.&lt;/P&gt;

&lt;P&gt;Here are two screenshots of the input: one upon loading the dashboard where the label doesn't load and one after I click on &lt;CODE&gt;Edit&lt;/CODE&gt; and &lt;CODE&gt;Cancel&lt;/CODE&gt; buttons:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8174i0ACD59601E0320DC/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Is there any trick I can use to ensure that the label loads correctly first time around?  For reference I am using Splunk 7.1.4.&lt;/P&gt;

&lt;P&gt;Thanks and best regards,&lt;/P&gt;

&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 10:02:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478839#M31401</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-01-03T10:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478840#M31402</link>
      <description>&lt;P&gt;Hello @andrewtrobec,&lt;/P&gt;

&lt;P&gt;You should clear the cache in SplunkWeb by calling the bump endpoint:&lt;BR /&gt;
    &lt;A href="https://mysplunkinstall/en-US/_bump"&gt;https://mysplunkinstall/en-US/_bump&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;replace mysplunkinstall by your hostname and then click on button bump and refresh your dashboard &lt;/P&gt;

&lt;P&gt;Let me know if it's works or not.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 13:01:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478840#M31402</guid>
      <dc:creator>Kawtar</dc:creator>
      <dc:date>2020-01-03T13:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478841#M31403</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;This is how I did it, without any tokens:&lt;/P&gt;

&lt;P&gt;add id attribute to your input: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form script="loadLabels.js"&amp;gt;
     ...
     &amp;lt;input type="multiselect" id="company"&amp;gt;
         ...
     &amp;lt;/input&amp;gt;
     ...
 &amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And use prepend in your .js:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$("#company").prepend('&amp;lt;label&amp;gt;Company&amp;lt;/label&amp;gt;');
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 14:13:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478841#M31403</guid>
      <dc:creator>roelscholte</dc:creator>
      <dc:date>2020-01-03T14:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478842#M31404</link>
      <description>&lt;P&gt;@roelscholte I tried doing this but it does not add the label.  Instead, the input field just displays the name of the token in place of the label.  Btw, I removed the &lt;CODE&gt;&amp;lt;label&amp;gt;&lt;/CODE&gt; tag completely from the dashboard XML assuming that the javascript would add it.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:42:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478842#M31404</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-01-03T15:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478843#M31405</link>
      <description>&lt;P&gt;@Kawtar Thanks for the suggestion, but unfortunately this does not work.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 16:10:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478843#M31405</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-01-03T16:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478844#M31406</link>
      <description>&lt;P&gt;@andrewtrobec try the following run anywhere example. I have used &lt;CODE&gt;&amp;lt;init&amp;gt;&lt;/CODE&gt; section to set the token for multiselect lavel. Which you can set via Simple XML JS extension as well.&lt;/P&gt;

&lt;P&gt;I have created an empty label for the multi-select i.e. &lt;CODE&gt;&amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;&lt;/CODE&gt; and then used &lt;CODE&gt;&amp;lt;html&amp;gt;&amp;lt;panel&amp;gt;&lt;/CODE&gt; to create my own div with multi-select label. Finally based on the multi-select position I have used &lt;CODE&gt;&amp;lt;style&amp;gt;&lt;/CODE&gt; tag to re-position label div above the multi-select  through CSS override.&lt;/P&gt;

&lt;P&gt;Please try out and confirm! &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Multiselect with token based label&amp;lt;/label&amp;gt;
  &amp;lt;init&amp;gt;
    &amp;lt;set token="tokMyMultiSelectLabel"&amp;gt;My Initial Label&amp;lt;/set&amp;gt;
  &amp;lt;/init&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;&amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;div id="my_multiselect_label"&amp;gt;$tokMyMultiSelectLabel$&amp;lt;/div&amp;gt;
        &amp;lt;style&amp;gt;
          #my_multiselect_label{
            position: absolute;
            top: -90px;
          }
        &amp;lt;/style&amp;gt;
      &amp;lt;/html&amp;gt;
      &amp;lt;input depends="$tokMyMultiSelectLabel$" id="myMultiSelect" type="multiselect" token="field1"&amp;gt;
        &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
        &amp;lt;choice value="all"&amp;gt;All&amp;lt;/choice&amp;gt;
        &amp;lt;choice value="alpha"&amp;gt;Alpha&amp;lt;/choice&amp;gt;
        &amp;lt;choice value="beta"&amp;gt;Beta&amp;lt;/choice&amp;gt;
        &amp;lt;delimiter&amp;gt; &amp;lt;/delimiter&amp;gt;
      &amp;lt;/input&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 16:36:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478844#M31406</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-01-03T16:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478845#M31407</link>
      <description>&lt;P&gt;@niketnilay This works well!  What would you suggest with multiple inputs?  I've taken your run anywhere and added a second input:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
   &amp;lt;label&amp;gt;Multiselect with token based label&amp;lt;/label&amp;gt;
   &amp;lt;init&amp;gt;
     &amp;lt;set token="tokMyMultiSelectLabel"&amp;gt;My Initial Label&amp;lt;/set&amp;gt;
     &amp;lt;set token="tokMyMultiSelectLabel2"&amp;gt;My Initial Label 2&amp;lt;/set&amp;gt;
   &amp;lt;/init&amp;gt;
   &amp;lt;fieldset submitButton="false"&amp;gt;&amp;lt;/fieldset&amp;gt;
   &amp;lt;row&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;html&amp;gt;
         &amp;lt;div id="my_multiselect_label"&amp;gt;$tokMyMultiSelectLabel$&amp;lt;/div&amp;gt;
         &amp;lt;style&amp;gt;
           #my_multiselect_label{
             position: absolute;
             top: -90px;
           }
         &amp;lt;/style&amp;gt;
       &amp;lt;/html&amp;gt;
       &amp;lt;input depends="$tokMyMultiSelectLabel$" id="myMultiSelect" type="multiselect" token="field1"&amp;gt;
         &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
         &amp;lt;choice value="all"&amp;gt;All&amp;lt;/choice&amp;gt;
         &amp;lt;choice value="alpha"&amp;gt;Alpha&amp;lt;/choice&amp;gt;
         &amp;lt;choice value="beta"&amp;gt;Beta&amp;lt;/choice&amp;gt;
         &amp;lt;delimiter&amp;gt; &amp;lt;/delimiter&amp;gt;
       &amp;lt;/input&amp;gt;

       &amp;lt;html&amp;gt;
         &amp;lt;div id="my_multiselect_label2"&amp;gt;$tokMyMultiSelectLabel2$&amp;lt;/div&amp;gt;
         &amp;lt;style&amp;gt;
           #my_multiselect_label2{
             position: absolute;
             top: -90px;
           }
         &amp;lt;/style&amp;gt;
       &amp;lt;/html&amp;gt;
       &amp;lt;input depends="$tokMyMultiSelectLabel2$" id="myMultiSelect2" type="multiselect" token="field2"&amp;gt;
         &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
         &amp;lt;choice value="all2"&amp;gt;All2&amp;lt;/choice&amp;gt;
         &amp;lt;choice value="alpha2"&amp;gt;Alpha2&amp;lt;/choice&amp;gt;
         &amp;lt;choice value="beta2"&amp;gt;Beta2&amp;lt;/choice&amp;gt;
         &amp;lt;delimiter&amp;gt; &amp;lt;/delimiter&amp;gt;
       &amp;lt;/input&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;Obviously this puts one label under the other which means that it's not lined up with the second input.  I suppose I should add a new panel on the same row.  Is that what you'd do?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 07:40:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/478845#M31407</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-01-09T07:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why are tokens set by a javascript file not working correctly when I load a dashboard?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/553894#M38458</link>
      <description>&lt;P&gt;Hi Andrew&lt;BR /&gt;&lt;BR /&gt;Try to add this code to your stylesheet&lt;BR /&gt;&lt;BR /&gt;label {&lt;BR /&gt;display: block !important;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;It force splunk to visualize your label even where you're refreshing your dashboard. Without it, the display option for fieldset's inputs is set by default as "none"&lt;BR /&gt;&lt;BR /&gt;Good Luck!!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 16:54:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-are-tokens-set-by-a-javascript-file-not-working-correctly/m-p/553894#M38458</guid>
      <dc:creator>Federico92</dc:creator>
      <dc:date>2021-06-01T16:54:35Z</dc:date>
    </item>
  </channel>
</rss>

