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.
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.
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;
}
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)?
Excellent! I tested it and it works!
Any updates on this?
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?
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.
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).
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.