Dashboards & Visualizations

Can I use JavaScript to call the selectFirstChoice property for a dropdown?

andrewtrobec
Motivator

Hello,

I'm looking to force a dropdown to revert to its first choice using JS. I already have a dropdown on my dashboard with id dropdown, but I don't know how to select it and set the selectFirstChoice property with JS. I've found examples that show how to create a new dropdown input, but in my case I have an existing one and I'm just trying to set selectFirstChoice to true.

Is it possible to do this?

Thanks!

Andrew

Labels (1)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Check this sample

<form script="dp.js">
  <label>dropdown_js</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="choice" id="dp">
      <label>field1</label>
      <choice value="one">one</choice>
      <choice value="two">two</choice>
    </input>
  </fieldset>
</form>

js:

require([
"jquery", 
"splunkjs/mvc", 
"splunkjs/mvc/simplexml/ready!"], function($, mvc) {

var dropdown = splunkjs.mvc.Components.get("dp");
dropdown.settings.set("selectFirstChoice",true);
});

View solution in original post

vnravikumar
Champion

Hi

Check this sample

<form script="dp.js">
  <label>dropdown_js</label>
  <fieldset submitButton="false">
    <input type="dropdown" token="choice" id="dp">
      <label>field1</label>
      <choice value="one">one</choice>
      <choice value="two">two</choice>
    </input>
  </fieldset>
</form>

js:

require([
"jquery", 
"splunkjs/mvc", 
"splunkjs/mvc/simplexml/ready!"], function($, mvc) {

var dropdown = splunkjs.mvc.Components.get("dp");
dropdown.settings.set("selectFirstChoice",true);
});

andrewtrobec
Motivator

@vnravikumar this is exactly it! Thank you so much! I was almost there. For anyone who is interested, I was reading this documentation: https://docs.splunk.com/DocumentationStatic/WebFramework/1.2/compref_dropdown.html

0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...