All Apps and Add-ons

How can I hide content on my view until a search runs?

Super Champion

I noticed that some stuff doesn't show up on your view until after the search has been started. For example, the ViewRedirectorLink module doesn't show the "View results" link until the search has been kicked off. Is it possible to do this with other modules too?

I'm specifically trying to hide some text in an HTML module (which is part of the Sideview Utils app). I'd like it to only show up after the search starts.

I'm looking for something fairly simple, if at all possible.

SplunkTrust
SplunkTrust

I'm afraid there's nothing that will be fairly easy, except for people who have a very good understanding of how the module framework methods work. Since these methods are only just beginning to have public documentation, I'm afraid there's not a lot of those people. Nonetheless, by reading the new docs and digging through the source code, it's certainly possible to become one of them and many have. http://dev.splunk.com/view/SP-CAAADQM#onContextChange

But this is the sort of thing I use what Sideview Utils calls a "custom behavior" for. In Sideview Utils there is a CustomBehavior module, and there is also a customBehavior param on every module. The former is safe to use if you know the basic methods of AbstractModule somewhat well. The latter is only safe to use if you know the specific Sideview module's methods very well.

The docs for custom behaviors are somewhat hidden but you can find a link to them on the 'Tools' page in Sideview Utils. However again, the key prerequisite for success concerns the workings of the module framework methods.

But pressing on, the simplest way I can think of is to nest your HTML module inside a CustomBehavior module, give that CustomBehavior module a 'customBehavior' param value of "onlyShowAfterSearchStarts", and then put the following code into application.js. Whether that's simple enough to be worth using, I dont know - It's certainly up to you.

// avoid throwing exceptions on views that dont have the SideviewUtils module.
if (typeof(Sideview)!="undefined") {
    // need to wait for all the modules to be initialized before we do it.
    $(document).bind("allModulesInitialized",function() {
        // iterates through all modules that specify the given custom behavior.
        Sideview.utils.forEachModuleWithCustomBehavior("onlyShowAfterSearchStarts", function(i,customBehaviorModule) {
            // modules can be shown or hidden by more than one piece of logic. 
            // in the end they are only actually shown if all the 'reasons' say they 
            // can be shown.  This is done by always passing args to show/hide methods.
            var ourReason = "onlyWhenSearchRunning"
            customBehaviorModule.onContextChange = function() {
                this.showDescendants(ourReason);
            }
            // hide it again when something dispatches the next search.
            customBehaviorModule.onBeforeJobDispatched = function() {
                this.hideDescendants(ourReason);
            }
        });
    }
}

Super Champion

Doh! I needed a splunkweb restart. (http://splunk-base.splunk.com/answers/24407/applicationjs-not-loading) Now "application.js" is loading, but it doesn't appear to be doing anything. I actually found different workaround that suites my needs; so I'm just going to assume that I'm doing something wrong and just walk away from this for now. (All the warnings with the custom behavior docs have scared me off.) Thanks for your help.

0 Karma

Super Champion

I'm having some trouble getting this to work; because "application.js" isn't being loaded by my view. Do I have to do something special to get that script to load?

0 Karma
State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!