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!

New Case Study Shows the Value of Partnering with Splunk Academic Alliance

The University of Nevada, Las Vegas (UNLV) is another premier research institution helping to shape the next ...

How to Monitor Google Kubernetes Engine (GKE)

We’ve looked at how to integrate Kubernetes environments with Splunk Observability Cloud, but what about ...

Index This | How can you make 45 using only 4?

October 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...