Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Typeahead updater not working

I try this:

$('input[name=recerv_country]').typeahead({
    remote : {
        url: '?country=%QUERY',
        filter: function(data) {
            var resultList = data.map(function (item) {   
                return item.name;
            });
            return resultList;
        }
    },
    updater : function (item) {
        //item = selected item
        //do your stuff.
        alert(item.name);
        alert('foo');
        alert('bar');
        //dont forget to return the item to reflect them into input
        return item;
    }
});

Nothing happens, alerts not appears. What I do wrong?

like image 406
NickNick Avatar asked Oct 12 '13 07:10

NickNick


2 Answers

$('input[name=recerv_country]').on('typeahead:selected', function(evt, item) {
    alert(item.value);
});
like image 173
NickNick Avatar answered Nov 03 '22 16:11

NickNick


With Twitter Bootstrap 3 the Typeahead plugin has been dropped. Bootstrap recommend to use https://github.com/twitter/typeahead.js in stead. You seem to use typeahead.js cause you use the remote call. Typeahead.js hasn't a updater function.

Check the custom events section of https://github.com/twitter/typeahead.js. typeahead:selected will fit your needs maybe.

See also: Bootstrap 3 typeahead.js, use similar functions from Bootstrap 2

like image 4
Bass Jobsen Avatar answered Nov 03 '22 15:11

Bass Jobsen