<?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: Javascript basesplunkview token update problem in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109399#M6189</link>
    <description>&lt;P&gt;Hi @mathu&lt;/P&gt;

&lt;P&gt;Glad you found your solution! Please be sure to accept your answer so other Splunk users with similar issues can refer to this post for help. &lt;/P&gt;

&lt;P&gt;Patrick&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jun 2014 18:04:40 GMT</pubDate>
    <dc:creator>ppablo</dc:creator>
    <dc:date>2014-06-19T18:04:40Z</dc:date>
    <item>
      <title>Javascript basesplunkview token update problem</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109395#M6185</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I've implemented a Splunk 6 javascript extension for a SimpleXML panel to show custom drilldown links for charts, tables, etc. The javascript dynamically inserts the link into the HTML DOM on page loading.&lt;/P&gt;

&lt;P&gt;The extension basically works (when the page loads), but if I use dropdown tokens, my drilldown link disappears.&lt;/P&gt;

&lt;P&gt;Here is the javascript code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;define(function(require, exports, module) {
    var _ = require('underscore');
    var mvc = require('splunkjs/mvc');
    var BaseSplunkView = require("splunkjs/mvc/basesplunkview");
    require("css!./linksearch.css");

    var LinkSearch = BaseSplunkView.extend({
        options: {
            managerid: null,
            searchstring: null
        },

        initialize: function(options) {
          this.configure();
          this.$div = $('&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;');
          this.settings.on("change:searchstring", this.render, this);
        },

        render: function() {
          this.$div.appendTo(this.$el);
          var uri = "https://splunksh/en-US/app/example-app/";
          var searchstring = this.settings.get('searchstring');
          var query = "search?q=search%20"+encodeURIComponent(searchstring);
          var link = uri+query;
          var a = $('&amp;lt;a&amp;gt;').attr("href", link).text("Link to Details");
          a.appendTo(this.$div);
          return this;
        },
    });
    return LinkSearch;
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and here is the Simple XML snippet&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[...]
&amp;lt;html id="panel1"&amp;gt;
  &amp;lt;h2&amp;gt;my panel&amp;lt;/h2&amp;gt;
  &amp;lt;div id="htmlcontent" 
        class="splunk-view" 
        data-require="app/example-app/components/htmlcontent/linksearch" 
        data-options='{
              "managerid":    "link-manager",
              "app_name":     "example-app",
              "searchstring": "index=test source=$source$ host=$host$"
     }'/&amp;gt;
&amp;lt;/html&amp;gt;
[...]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On a token-update, the DOM changes, but my render function does not get called.. why?&lt;/P&gt;

&lt;P&gt;kind regards&lt;BR /&gt;
Mathias&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2014 11:25:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109395#M6185</guid>
      <dc:creator>mathu</dc:creator>
      <dc:date>2014-06-18T11:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript basesplunkview token update problem</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109396#M6186</link>
      <description>&lt;P&gt;Token replacement does not work inside HTML element attributes, such as in the "data-options" attribute above.&lt;/P&gt;

&lt;P&gt;I'd recommend instantiating the custom view manually from a JS extension instead. For example:&lt;/P&gt;

&lt;P&gt;Simple XML snippet:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;html id="panel1"&amp;gt;
    &amp;lt;div id="htmlcontent"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;JS Extension:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    'app/example-app/components/htmlcontent/linksearch', 'jquery', 'splunkjs/ready!'
], function(LinkSearch, $, mvc) {
    new LinkSearch({
        el: $('#htmlcontent'),
        managerid: 'link-manager',
        app_name: 'example-app',
        searchstring: mvc.tokenSafe('index=test source=$source$ host=$host$')
    }).render();
});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jun 2014 17:42:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109396#M6186</guid>
      <dc:creator>dfoster_splunk</dc:creator>
      <dc:date>2014-06-18T17:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript basesplunkview token update problem</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109397#M6187</link>
      <description>&lt;P&gt;There is a way to use token replacement inside HTML panels.  Have a look at: &lt;BR /&gt;
&lt;A href="http://answers.splunk.com/answers/109260/splunk6-custom-html-visualization-not-updating-if-form-input-changes"&gt;http://answers.splunk.com/answers/109260/splunk6-custom-html-visualization-not-updating-if-form-input-changes&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The trick is to use type "token_safe" and two dollar signs ($$token$$) for a token replacement instead of just one ($token$)&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2014 07:12:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109397#M6187</guid>
      <dc:creator>mathu</dc:creator>
      <dc:date>2014-06-19T07:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript basesplunkview token update problem</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109398#M6188</link>
      <description>&lt;P&gt;.. found the answer by myself &lt;/P&gt;

&lt;P&gt;using double dollar signs in the simple xml and listen to the correct on-change event&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[..]
this.settings.on("change:searchstring", this.render, this);
[..]


[..]
&amp;lt;html id="panel1"&amp;gt;
  &amp;lt;div id="htmlcontent" 
        class="splunk-view" 
        data-require="app/jmx_ta/components/htmlcontent/linksearch" 
        data-options='{
            "managerid":    "link-manager",
        "app_name":     "jmx_ta",
        "searchstring": {"type": "token_safe", "value": "index=test source=$$source$$ host=$$host$$"}
     }'/&amp;gt;
&amp;lt;/html&amp;gt;
[..]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jun 2014 07:16:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109398#M6188</guid>
      <dc:creator>mathu</dc:creator>
      <dc:date>2014-06-19T07:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript basesplunkview token update problem</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109399#M6189</link>
      <description>&lt;P&gt;Hi @mathu&lt;/P&gt;

&lt;P&gt;Glad you found your solution! Please be sure to accept your answer so other Splunk users with similar issues can refer to this post for help. &lt;/P&gt;

&lt;P&gt;Patrick&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2014 18:04:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-basesplunkview-token-update-problem/m-p/109399#M6189</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2014-06-19T18:04:40Z</dc:date>
    </item>
  </channel>
</rss>

