Typeahead problems with Bootstrap 3.0 RC1

前端 未结 5 1866
一个人的身影
一个人的身影 2020-11-30 04:08

I\'m trying to use Twitter Typeahead with Bootstrap 3 RC1, because Bootstrap dropped its own typeahead plugin on version 3.

I\'m using the following HTML on my form:

5条回答
  •  旧时难觅i
    2020-11-30 04:55

    After a lot of research with no luck at all adding styles, I finally fixed it adding one line inside the constructor Typeahead (bootstrap.js or bootstrap-typeahead.js depending on your version):

    this.$menu.width(this.$element.outerWidth());

    Here's the code:

    /* TYPEAHEAD PUBLIC CLASS DEFINITION
     * ================================= */
    
    var Typeahead = function (element, options) {
        this.$element = $(element)
        this.options = $.extend({}, $.fn.typeahead.defaults, options)
        this.matcher = this.options.matcher || this.matcher
        this.sorter = this.options.sorter || this.sorter
        this.highlighter = this.options.highlighter || this.highlighter
        this.updater = this.options.updater || this.updater
        this.source = this.options.source
        this.$menu = $(this.options.menu)
        this.shown = false
        this.listen()
        this.$menu.width(this.$element.outerWidth());
    }
    

提交回复
热议问题