I'm trying to implement a dropdown box to show search options, much the way the Stack Overflow tag search box works. The search itself is working great, but I can't get the box to show up at the right times.

Here's the template:

```html
<div class="dropdown">
    <input class="entryInput" id="query" name="query" type="text"
        data-toggle="dropdown"/>
    <ul class="dropdown-menu" role="menu" aria-labelledby="query">
        {{#each queryResults}}
            <li><a class="result" data-id="{{_id}}">{{firstname}}</a></li>
        {{/each}}
    </ul>
</div>

```

This code works, and the list displays in the dropdown, but it displays an empty stub when the input is first clicked (see my screencap to see what that empty stub looks like), and disappears when I begin typing.

Elsewhere in my app, I manage `Session.get('query')` and `Session.get('queryPopulated')`, which are the values I want this dropdown to react to. `query` is simply storing the query itself in real-time, and `queryPopulated` is a boolean that is set when the user **chooses** a result. I want the dropdown to stay active as long as these things are true:

* the input has focus;
* the `query` is valid (so no showing a lame stub);
* and `queryPopulated` is false (because there's no more reason to display, the user chose a result).

The [Bootstrap docs](http://getbootstrap.com/javascript/#dropdowns) only provide a `toggle` method, and that just isn't really fine-grained enough. I need to manually take control of the dropdown's reactions, and I'm not sure how to do that with the events and methods it's exposed.

How do I override the behavior?

Here's what that lame stub looks like.

![Here's what that lame stub looks like.](https://i.stack.imgur.com/9jgrR.png)

Thanks in advance!

Update
------

I now have this javascript managing the dropdown:

```js
Template.entryStudentInput.rendered = function() {
    $('.dropdown').on('shown.bs.dropdown', function(){
        console.log('show');
        if(!Session.get('query')) {
            console.log('query is false in show');
            $('.dropdown').dropdown('toggle');
        }
    });
};

```

That block above successfully prevents the dropdown from showing when empty, but I can't get the dropdown to show again once the query is valid.

Here's another block, meant only as an experiment, reacting to key events:

```
Template.entryStudentInput.events({
    'keyup #query': function(e, t) {
        console.log('should toggle');
        $('dropdown').dropdown('toggle');
        // These didn't work either.
        // $(t.find('.dropdown')).dropdown('toggle');
        // t.find('.dropdown').dropdown('toggle');
    }
});

```

It should simply toggle back and forth every time a key is pressed, but it doesn't do anything at all. The `console` log shows up just like it should, but there's no change whatsoever on the dropdown. It seems like I just have no control over the dropdown from anywhere but the `$('.dropdown').on` event handlers.