Dashboards & Visualizations

Setup.xml dropdown list

sarumjanuch
Path Finder

Who knows, how to implment dropdow for setup.xml, i can se in documentation that there is type "list", but here shoud i pupulate values for it?

Tags (3)

VatsalJagani
SplunkTrust
SplunkTrust

Hello @sarumjanuch and @harshpatel,

Right now I don't have full solution implemented but what you can do is:

  • From your python handler convert your list to string and provide in normal text field on setup page (textField-1)
  • Create another text field with default value of dropdown (textField-2)
  • Write application.js file and put under appserver/static
  • Write method $(document).ready(function() {
  • Inside that write code to follow below steps
  • Hide above textField-1 and textField-2
  • Get value from that textField1, convert it to Js list
  • Use above Js list and create select (dropdown)
  • Use value from textField-2 to select default value in dropdown
  • Write function $(".splButton-primary").on("click", function(e){ and add code to read the selected value from the dropdown and put that value in textField-2

Hope this helps to understand the flow how you can implement it.

0 Karma

aronsemle
New Member

This works. Here is my application.js and setup.xml file for anyone else fighting with this. Splunk please add support... it's a lot of work for a list...

The only other thing is to make sure your default/my_app.conf file has the list values for your placeholder. Hope this helps.

$(document).ready(function() {
    auth_type_placeholder_div_id = "item-/my_app_setup/my_app_1/my_app_1/authentication_type_placeholder"
    auth_type_input_id = "/my_app_setup/my_app_1/my_app_1/authentication_type_id"
    auth_type_id = "/my_app_setup/my_app_1/my_app_1/authentication_type_id"
    auth_type_placeholder_id = "/my_app_setup/my_app_1/my_app_1/authentication_type_placeholder_id"

    // hide the auth inputs auth inputs
    document.getElementById(auth_type_placeholder_div_id).style.display='none'
    document.getElementById(auth_type_input_id).style.display='none'

    // convert the values in placeholder (comes from default/my_app.conf) to an array for the select
    list_of_values = document.getElementById(auth_type_placeholder_id).value.split(',')

    // create a select with the auth input is
    auth_div = document.getElementById(auth_type_input_id)
    frag = document.createDocumentFragment()
    select = document.createElement("select")
    select.id = "auth_type_select"
    select.style.visibility='visible'
    for (index = 0; index < list_of_values.length; index++) { 
        select.options.add(new Option(list_of_values[index]))
    } 
    frag.appendChild(select)
    auth_div.parentNode.insertBefore(frag, auth_div.nextSibling);

    // select the current value
    select.value = document.getElementById(auth_type_id).value
});

$(".splButton-primary").on("click", function(e){
    // get the value of the selection
    document.getElementById(auth_type_id).value = document.getElementById('auth_type_select').value
});

<setup>
    <block title="my_app Credentials" endpoint="my_app_setup/my_app_1" entity="my_app_1">
        <input field="username">
            <label>Username*</label>
            <type>text</type>
        </input>
        <input field="password">
            <label>Password*</label>
            <type>password</type>
        </input>
        <input field="authentication_type_placeholder">
            <label>hidden field to get auth values,native,basic,form</label>
            <type>text</type>
        </input>
        <input field="authentication_type">
            <label>my_app Authentication</label>
            <type>text</type>
        </input>
    </block>
</setup>
0 Karma

harshpatel
Contributor

@sarumjanuch , Any updates? Did you find any answer?

0 Karma

LukeMurphey
Champion

I don't believe that lists were ever fully implemented in setup.xml. You could fake it by including your own JavaScript though.

sarumjanuch
Path Finder

That is actualy waht i did. If someone need, i cant post it here.

0 Karma

gaurav_maniar
Builder

Hi Sarumjanuch,

can you please post your solution?

0 Karma
Get Updates on the Splunk Community!

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud  In today’s fast-paced digital ...

Observability protocols to know about

Observability protocols define the specifications or formats for collecting, encoding, transporting, and ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...