Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Merge requests
  • !4025

Typeahead render method.

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/gcoop/typeaheadrender into 2.1.0-wip Jul 07, 2012
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 7

Created by: gcoop

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]
  }
})
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/gcoop/typeaheadrender