Getting Data In

How to clear text input after submitting?

clairebesson
Explorer

Hi everyone,

I have created a drop-down linked with text input. I am able to search by field1, field2, field3. However, I have an issue to clear text input after submitting:

For example:
1) I enter a text in “search by field1” and submit.
2) It displays the line
3) I go on “Search by field2”
4) I return on “Search by field1” and the text that I have written at 1) is still in the text input

I want that when I return in "Search by field1", the text was cleared and displays the default value *.
I tried to create a clear button but didn’t work:
I add this to my code :

<html>
      <input type="button" value="Clear" id="clear></input>
      </html>

and the javascript function clear.js :
var input = document.querySelector('#clear');
var textarea = document.querySelector('#output');

input.addEventListener('click', function () {
    textarea.value = '';
}, false);

Is there another way to clear text input ? Could you please help me with that ?
Thanks in advance

Tags (4)
0 Karma

bmacias84
Champion

I would recommend reviewing the component reference for Splunk Web. Using Javascript you can select splunk object by id and most Splunk objects how multiple event listeners.

//using TextInputView and MultiDropdownView

var hostInput = splunkjs.mvc.Components.getInstance("host-input");
var dropdownManager = splunkjs.mvc.Components.getInstance("multidropsearch1");

dropdownManager.on('change', function() {
  hostInput.settings.set("value", '')
})

This is only a snippet. If you want to add an event listener I would start by extending backbone object to added an on click event. Just the on change should meet your need.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...