Dashboards & Visualizations

Is it possible to create a textarea in HTML and have it behave like a textfield?

syx093
Communicator

I want to create a textarea in a dashboard. What I want to happen is when I enter IP Addresses into the textarea, I want the contents of the textarea to be placed in a token just like a textfield. Then I can search for the IP Address. How would I go about doing that.

Vijeta
Influencer

How did it work?I am triying to use a textarea in my dashboard form but unable to pass its values in any token using the above script and css. I need to do it for users so they are able to enter comments also use new line feature which can be done by text area. But I am not able to get the text area value in the token.

0 Karma

piUek
Path Finder

I have a solution for this problem:
It consist of 2 files - textarea.js, textarea.css which You add to your application appserver/static folder.
In your dashboard definition you add 'script="textarea.js" stylesheet="textarea.css">' to your root element
(for example in the first line).
Then You add your text area to the fieldset:

<html>
  <label>Comment</label>
  <textarea rows="3" id="ta_task_comment"></textarea>
</html>

Where text area id is your token name with "ta_" prefix.

textarea.js:

require([
  'underscore',
  'jquery',
  'splunkjs/mvc',
  'splunkjs/mvc/tableview',
  'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
  var defaultTokenSpace = mvc.Components.getInstance('default');
  $('textarea').parent().parent().addClass('textarea_div');
  $('textarea').each(function (ta) {
    $(this).on('input', function(input) {
      defaultTokenSpace.set($(this).attr('id').replace('ta_' ,'') ,$(this).val());
    })
  })
});

textarea.css:

    .textarea_div {
        display: inline-block;
        width: 200px;
        margin-right: 50px;
    }

alwayslearning
Explorer

This JavaScript executes on input. Can you help me with the same problem but I want the JavaScript execute when the user clicks on a html button instead (i.e. it grabs the content of the textarea and creates a splunk token)?

0 Karma

Dev999
Communicator

Excellent! I tested it and it works!

0 Karma

rharrisssi
Path Finder

Any updates on this?

0 Karma

LukeMurphey
Champion

Could you clarify why you want to have a textarea instead of a input? Is it because you want the ability to specify multiple IP addresses?

0 Karma

syx093
Communicator

Textarea expands when you copy and paste IP Addresses in them while text fields does not. Because text areas allow you to do this, you can see which IP Addresses you have pasted into the textarea. This makes it easier to see what might have gone wrong. Plus, it is more visually appealing and executive friendly.

0 Karma

LukeMurphey
Champion

That makes sense. I was asking because there is a multi-select input too and I was wondering if that would work (it can be modified to allow entering custom values).

0 Karma

syx093
Communicator

I was thinking about doing that but I was told to that the executives wants to be able to copy and paste these IP Addresses into the textarea. I believe that they do not want to manually input all say 100 IP Addresses into a multi-select.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...