Thursday, August 27, 2015

Prepend Items to Bootstrap Typeahead

This is a little code snippet for manually adding static items along with typeahead suggestions list. This can be used to prepend or append items. I'm using biggora/bootstrap-ajax-typeahead

You only need to look for render event of the plugin and inject your code.

[sourcecode language="javascript"]
$("#customer").typeahead({
        onSelect: function(item) {
            ...
        },
        updater: function(item) {
            return item;
        },
        highlighter: function(name) {
           ...
        },
        ajax: {
            ...
            },
           
        render: function(items) {
            var uber = {render: $.fn.typeahead.Constructor.prototype.render};
            uber.render.call(this, items);
            this.$menu.prepend('<li class="nostyle"><a href="#" autocomplete="off" data-toggle="modal" data-target="#itemModal"><i class="fa fa-plus"></i> New Customer</a></li>');
            return this;
        }
    });
[/sourcecode]

 

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...