In typeahead, which event triggered when I choose empty template?

762 views Asked by At

I want to call a function when I choose empty template in twitter-bootstrap typeahead. Is there any event to do this?

In the following code, on('typeahead:selected', fn) event triggers when I click returned one of returned values. After this event triggers, I continue to type some worlds that will not return value. In this case, I want to empty my global object (i.e myObject=null) when I click No suggestion section.

Here is code:

$('#myinput').typeahead({
                minLength: 1,
                highlight: true,
            },
            {
                name: 'myinput',
                displayKey: 'displayName',
                templates: {
                    empty: [
                    '<div>',
                    'No suggestion',
                    '</div>'
                    ].join('\n'),
                    suggestion: function (val) {
                        return '<div>' + val.value + '</div>'
                    }
                },
                source: function (query, cb) {
                    $.ajax({
                            url: "...",
                            data: "...",
                            success: function(result){
                                cb(result);
                            }
                    });
                }
            }).on('typeahead:selected', function (event, data) {
                    myObject = data;
            });
0

There are 0 answers