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 This Month in Splunk Observability Cloud - Metrics Usage Analytics, Enhanced K8s ...

The latest enhancements across the Splunk Observability portfolio deliver greater flexibility, better data and ...

Alerting Best Practices: How to Create Good Detectors

At their best, detectors and the alerts they trigger notify teams when applications aren’t performing as ...

Discover Powerful New Features in Splunk Cloud Platform: Enhanced Analytics, ...

Hey Splunky people! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2408. In this ...