All Apps and Add-ons
Highlighted

How to set the default value for a dynamically populated Pulldown?

Communicator

I enjoy using Sideview Utils in my custom views, especially PullDown controls.

The only thing I can't find in neither documentation nor answers, is how to set up default value for the PullDown when it is populated dynamically by a search. This value is one from the dynamic list and I exactly know what it is.

For example, the search gives me the following results:
Host1
Host2
Host3

I want the PullDown default selection to be set as Host2.

How is that possible to implement?

Of course, I can assign an additional static field [label=(Default: Host2); value=Host2] and it will become the default. But it doesn't look very nice as it duplicates actual Host2.

Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

SplunkTrust
SplunkTrust

I have been meaning to add this to the documentation for some time and I should have gotten this done long ago. Sorry!

What you do, is add a ValueSetter module upstream from the Pulldown module. Set the "name" param of the ValueSetter to the same value as the Pulldown's "name" param, and set the value param to the value you wish to preselect, in this case "Host2".

Down the road I want to add a param to Pulldown so that it can do this preselection for itself as well, but I haven't done it yet.

PS. Technically there's another solution as well. Assuming you have a URLLoader module at the top of your view, and say your Pulldown module has as its "name" param a value like "myPulldownName", then you can pass ?myPulldownName=Host2 on the URL, and that will preselect the view's Pulldown with "Host2".

Normally in default.xml (the file in the app that controls the app navigation menu dropdowns), you would refer to a view as <view name="myView"/>, however you can also specify the link explicitly as <a href="myView?myPulldownName=Host2">Go to My View</a> and preselecting Pulldown and TextField modules in this way can be quite a useful trick...

View solution in original post

Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

Communicator

Cool, it works!
The first solution, nice and easy, thank you Nick!

0 Karma
Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

Path Finder

On a slightly different note, @sideview, is it possible to implement a pulldown switcher in a chart to modify a search string in Simple XML?

0 Karma
Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

SplunkTrust
SplunkTrust

No, you can't do anything like this in the Simplified XML I'm afraid.

0 Karma
Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

Splunk Employee
Splunk Employee

A warning about the ValueSetter solution: if you do navigate to the page in question with the querystring specifying what the Pulldown's value should be, the querystring value will be overridden unconditionally by the ValueSetter value.

0 Karma
Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

SplunkTrust
SplunkTrust

True, but that's what ValueSetter's "allowClobber" param is for. Here's the description from the conf:

"allowClobber: Leave this empty and ValueSetter will set the fields, assuming logic from requiredKeys says to do so. Set this to False, and ValueSetter will NOT clobber existing values from upstream. In cases where ValueSetter is used only to preselect a Pulldown module, but values are sometimes populated from the URL (ie URLLoader) you will probably want to set this to False."

Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

SplunkTrust
SplunkTrust

one addition - subsequent to all this a proper docs page for ValueSetter was indeed added, as well as another page specifically about just how to use ValueSetter to prepopulate the selected option (or multiselect options plural) in a Pulldown module.

0 Karma
Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

Communicator

One small question: how can I hide the default static value "All" if no static fields specified? So far I can simply hack Pulldown.html and Pulldown.js by removing {"label":"All", "value":"*"} from the appropriate functions and leaving blank [].

Is there any official way? 😉

0 Karma
Highlighted

Re: How to set the default value for a dynamically populated Pulldown?

SplunkTrust
SplunkTrust

This is technically a separate question, but there's a page in the Sideview Utils docs specifically about this. It's called "Pulldown - configuring the 'all' options". Read the Sideview Utils docs! It's worth the time spent! 😃

0 Karma