Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeahead render method. #4024

Closed
wants to merge 3 commits into from
Closed

Typeahead render method. #4024

wants to merge 3 commits into from

Conversation

gcoop
Copy link
Contributor

@gcoop gcoop commented Jul 7, 2012

Exposed typeahead render method so you can override it and customise the list html based on the type of object returned from a custom source. You need this if you want to produce something like the new twitter search/autocomplete.

Changed .next() to use .nextAll(':has(a):first') so you can have

  • separating result types.

    Example

    
    var labels
      , mapped
    $("input").typeahead({
      source: function (query, process) {
        $.get('/autocomplete', { q: query }, function (data) {
          labels = []
          mapped = {}
    
          $.each(data, function (i, item) {
            mapped[item.label] = item.value
            labels.push(item.label)
          })
    
          process(labels)
        })
      },
      render: function () {
          var that = this
    
          items = $(mapped).map(function (i, item) {
            i = $(that.options.item).attr('data-value', item)
    
            if (item.thumb) { // Ok object has a thumbnail.
              i.find('a').append(''+that.highlighter(item));
            } else {
              i.find('a').html(that.highlighter(item))
            }
    
            return i[0]
          })
    
          items.first().addClass('active')
          this.$menu.html(items)
      },
      updater: function (item) {
        return mapped[item]
      }
    })
    

    @gcoop gcoop closed this Jul 7, 2012
    @travisbot
    Copy link

    This pull request passes (merged ed0830c into 7ff1b07).

    @niftylettuce
    Copy link

    Did this get removed? I don't see it here: https://github.com/twitter/bootstrap/blob/2.1.0-wip/js/bootstrap-typeahead.js#L38

    @ioleo
    Copy link

    ioleo commented Aug 18, 2012

    +1

    whats the status of render method, will it be part of TB 2.1 ?

    @alexhanh
    Copy link

    +1

    @Decad
    Copy link

    Decad commented Apr 11, 2013

    has this been removed?

    would be nice to have

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    6 participants