Dashboards & Visualizations

Why search is not taking input from textarea when clicked on decode button?"| eval encoded="$input_encoded$"

ajayjuneja
Loves-to-Learn Lots

<form version="1.1" theme="dark">
<label> Backtrace</label>
<init>
<unset token="input_encoded"></unset>
<unset token="show"></unset>
</init>
<fieldset autoRun="true" submitButton="false">
<input type="dropdown" token="appBranchName" searchWhenChanged="true">
<label>Select appBranchName:</label>
<fieldForLabel>appBranchName</fieldForLabel>
<fieldForValue>appBranchName</fieldForValue>
<search>
<query>| makeresults count=1
| table appBranchName</query>
<earliest>-30d@d</earliest>
<latest>now</latest>
</search>
</input>
<input type="dropdown" token="build" searchWhenChanged="true">
<label>Select Build-Id:</label>
<fieldForLabel>build</fieldForLabel>
<fieldForValue>build</fieldForValue>
<search>
<query>
<![CDATA[
| makeresults
| table build
]]>
</query>
<earliest>-30d@d</earliest>
<latest>now</latest>
</search>
</input>
</fieldset>
<search>
<query>
| makeresults count=1
| eval encoded="$input_encoded$"
| eval branch="$appBranchName$"
| eval buildId="$build$"
| table encoded  branch buildId
</query>
<done>
<set token="backtrace_show">$result.decoded$</set>
</done>
</search>
<row>
<panel>
<title>Encoded</title>
<html>
<textarea id="input_encoded" style="width: 100%; height: 250px;"></textarea>
<input id="decode" type="button" value="Decode" style="width: 180px;height: 40px;"/>
</html>
</panel>
</row>
<row depends="$show$">
<panel>
<title>backtrace</title>
<html>
<textarea id="output" style="width: 100%; height: 300px;">$how$</textarea>
</html>
</panel>
</row>
</form>

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@ajayjuneja - Its because input_encoded is HTML input and not Splunk Input Filter.

* You see with HTML input there is no token binding.

* Either you use Splunk's Text Input Filter instead of HTML textarea.

* Or you need to manually bind the HTML text input value with a token with custom Javascript handler.

    // Get a reference to the textarea element
    var textarea = document.getElementById('input_encoded');
    var tokens = mvc.Components.getInstance('default');
    var submittedTokens = mvc.Components.getInstance('submitted');

    // Add an event listener to capture textarea input changes
    textarea.addEventListener('input', function() {
      // Get the current value of the textarea
      var newValue = textarea.value;

      // Update the Splunk token value
      tokens.set('input_encoded', newValue);
      submittedTokens.set('input_encoded', newValue);
    });

(Above is not the complete code, but for your reference, how you can achieve this in Splunk JS.)

 

I hope this helps!!! Kindly upvote if it does!!!

0 Karma
Get Updates on the Splunk Community!

Enter the Dashboard Challenge and Watch the .conf24 Global Broadcast!

The Splunk Community Dashboard Challenge is still happening, and it's not too late to enter for the week of ...

Join Us at the Builder Bar at .conf24 – Empowering Innovation and Collaboration

What is the Builder Bar? The Builder Bar is more than just a place; it's a hub of creativity, collaboration, ...

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...