<?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: Setting text input with javascript in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709573#M58024</link>
    <description>&lt;P&gt;Thanks for the observation. The problem is that, even if I comment the highlighted row, the event of clicking the submit button works only the first time I click, the following times it doesn't event print "CLICKED". I'm more interested in solving that issue, because I don't understand why it is working like that.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2025 09:50:52 GMT</pubDate>
    <dc:creator>sassofrasso</dc:creator>
    <dc:date>2025-01-23T09:50:52Z</dc:date>
    <item>
      <title>Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709224#M58006</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone!&amp;nbsp;&lt;BR /&gt;I'm trying to create a dashboard and set some tokens through javascript.&lt;BR /&gt;I have some html text inputs and I want that, on the click of a button, they set the corresponding tokens to the inputted value.&amp;nbsp;&lt;BR /&gt;However, when I try to click again the button, the click event doesn't trigger. Can you help me?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function (_, $, mvc) {
    
    function setToken(name, value) {
      mvc.Components.get("default").set(name, value);   
      mvc.Components.get('submitted', {create: true}).set(name, value);    
    }
    /* ----------------------- */
    let prefix = mvc.Components.get("default").get('personal_input_prefix') ?? "personal_";

    // Setting tokens for Inputs with prefix ${prefix}

    $('#personal_submit').on('click', function(e){
        e.preventDefault();        
        console.log("CLICKED");
        let input_text = $("input[type=text]");
        for (let element of input_text) {     
            let id = element.id;            
            if (id !== undefined &amp;amp;&amp;amp; id.startsWith(prefix)){
                let value = element.value;
                setToken(`${id}_token`, value);                     // &amp;lt;---
                document.getElementById(`${id}_token_id`).innerHTML = value;
                // Set token ${id}_token to value ${value}
            }
        }        
    });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;DASHBOARD&amp;nbsp;EXAMPLE:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form version="1.1" theme="light" script="test.js"&amp;gt;
  &amp;lt;label&amp;gt;Dashboard test&amp;lt;/label&amp;gt; 
    &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
      &amp;lt;input id="personal_valueA" type="text"/&amp;gt;
      &amp;lt;input id="personal_valueB" type="text"/&amp;gt;
      &amp;lt;button id="personal_submit" class="primary-btn"&amp;gt;Click&amp;lt;/button&amp;gt;
      &amp;lt;br/&amp;gt;
      Show:
      &amp;lt;p id="personal_valueA_token_id"&amp;gt;$personal_valueA_token$&amp;lt;/p&amp;gt;
      &amp;lt;p id="personal_valueA_token_id"&amp;gt;$personal_valueB_token$&amp;lt;/p&amp;gt;
    &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 09:47:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709224#M58006</guid>
      <dc:creator>sassofrasso</dc:creator>
      <dc:date>2025-01-20T09:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709262#M58007</link>
      <description>&lt;P&gt;Do you get the CLICKED message in the console log or any other message? I assume you've looked at the dashboard examples for setting tokens on buttons, as your code is similar.&lt;/P&gt;&lt;P&gt;If you add logging to the base code, does anything get logged at all.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 22:37:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709262#M58007</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-20T22:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709277#M58008</link>
      <description>&lt;P&gt;No, the second time i click on the button it does not log "CLICKED" nor anything at all. It is as if I'm not clicking the button, and it doesn't print errors nor warnings&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 08:12:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709277#M58008</guid>
      <dc:creator>sassofrasso</dc:creator>
      <dc:date>2025-01-21T08:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709427#M58013</link>
      <description>&lt;P&gt;Other than debugging the JS, I can only question if you need to do this in JS - Splunk inputs do this out of the box. Are you using JS for a specific reason that the out of the box stuff does not handle?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 07:20:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709427#M58013</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-22T07:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709438#M58014</link>
      <description>&lt;P&gt;I am using JS because I need to embed the input in an html section to perform further customizations, and Splunk input doesn't allow me to do them.&lt;/P&gt;&lt;P&gt;Regarding the JS, the problem has something to do with the button and the setToken function: if i comment the line&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;setToken(`${id}_token`, value);                     // &amp;lt;---&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;the button responds to each click without problems, but when I decomment the line it triggers only on the first button click and then no more. I cannot understand why&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 08:16:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709438#M58014</guid>
      <dc:creator>sassofrasso</dc:creator>
      <dc:date>2025-01-22T08:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709517#M58017</link>
      <description>&lt;P&gt;In Developer tools you posted example gives this&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bowesmana_0-1737578605602.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34217iAFB4C0440595F0FD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bowesmana_0-1737578605602.png" alt="bowesmana_0-1737578605602.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 20:43:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709517#M58017</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-22T20:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709519#M58018</link>
      <description>&lt;P&gt;Seems like your problem is that the ID in your XML is wrong - you have duplicated&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;      &amp;lt;p id="personal_valueA_token_id"&amp;gt;$personal_valueA_token$&amp;lt;/p&amp;gt;
      &amp;lt;p id="personal_valueB_token_id"&amp;gt;$personal_valueB_token$&amp;lt;/p&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Your original duplicates the personal_valueA_token_id&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;      &amp;lt;p id="personal_valueA_token_id"&amp;gt;$personal_valueA_token$&amp;lt;/p&amp;gt;
      &amp;lt;p id="personal_valueA_token_id"&amp;gt;$personal_valueB_token$&amp;lt;/p&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Jan 2025 20:49:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709519#M58018</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-22T20:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709573#M58024</link>
      <description>&lt;P&gt;Thanks for the observation. The problem is that, even if I comment the highlighted row, the event of clicking the submit button works only the first time I click, the following times it doesn't event print "CLICKED". I'm more interested in solving that issue, because I don't understand why it is working like that.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 09:50:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709573#M58024</guid>
      <dc:creator>sassofrasso</dc:creator>
      <dc:date>2025-01-23T09:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Setting text input with javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709641#M58033</link>
      <description>&lt;P&gt;Interesting - I see now - yes, you can see that at the start there are event listeners for the button&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bowesmana_0-1737670409928.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34226i2A36C9531B9E4B02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bowesmana_0-1737670409928.png" alt="bowesmana_0-1737670409928.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;but once the first call to set(name, value) in SetToken is called, it will remove the event listener, when this trigger() function is called as the value changes. Don't know why, but it doesn't get reset, so there is no longer an event listener&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bowesmana_1-1737672393006.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/34227iBB618D8E1A173D98/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bowesmana_1-1737672393006.png" alt="bowesmana_1-1737672393006.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 23:04:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Setting-text-input-with-javascript/m-p/709641#M58033</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-01-23T23:04:03Z</dc:date>
    </item>
  </channel>
</rss>

