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. #4025

Closed
wants to merge 1 commit into from
Closed

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 <li class="divider"></li> 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]
  }
})

@travisbot
Copy link

This pull request passes (merged 1c4410a into 7ff1b07).

@ioleo
Copy link

ioleo commented Jul 8, 2012

+1 This is useful

@jensenkd
Copy link

+1

@lookfirst
Copy link
Contributor

+1!!!!!!!!!!!!!

@fat
Copy link
Member

fat commented Jul 22, 2012

Hey @gcoop,

Thanks for opening this pull-request! Unfotunately, it looks like it fails to pass the tests neccessary for submitting to bootstrap. The following tests are currently failing:

  • should always include a unit test if changing js files

For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines.

thanks!

@fat fat closed this Jul 22, 2012
@niftylettuce
Copy link

Please see my comment here #4024 (comment). We should make sure this is integrated. It is critical for things like search query auto-complete (e.g. so you don't need JS for click events).

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

Successfully merging this pull request may close these issues.

None yet

7 participants