Giter Site home page Giter Site logo

backbone-autocomplete's Introduction

backbone-autocomplete

TODO

  • api to change autocomplete input field
  • unit tests
  • fix TODOS
  • update docs to better explain how to use each method
  • add package.json

A progressively enhanced autocomplete field powered by backbone.js and underscore.js

Overview

html:

<div class="autocomplete">
  <form action="/search">
    <input type="text" placeholder="Search...">
    <ul class="autocomplete-results" style="display: none"></ul>
  </form>
</div>

coffee:

document.ready ->
  c = new AutocompleteItems [
    { name: 'apple'   , kind: 'fruit'    , token: '#' },
    { name: 'orange'  , kind: 'fruit'    , token: '#' },
    { name: 'carrot'  , kind: 'vegetable', token: '@' },
    { name: 'broccoli', kind: 'vegetable', token: '@' },
  ]
  v = new AutocompleteItemsView(
    el: $('.autocomplete')
    collection: c
  )

Options

Required

  • el: an element containing a input[type=text] field
  • collection: a AutocompleteItems collection

Optional

  • itemView: a subclass of AutocompleteItemView if you need custom behavior

Methods

  • submit()

    • submits the parent form. if needed, finishes autocomplete from selected result
  • showResults()

    • shows autocomplete results
  • hideResults()

    • hides autocomplete results
  • selectResult(index = 0)

    • selects the autocomplete item at the given index. does not submit the form.

Behavior

  • typing or copy/paste into the field shows autocomplete results
    • each autocomplete result shows matching substrings within tags
  • clearing the input field hides autocomplete results
  • cycle through autocomplete results with mouse hover or up/down arrow keypress
  • select an autocomplete result with mouse click or enter keypress
    • selecting also submits the form containing the autocomplete field
  • after submit, the field blurs and autocomplete results are hidden

Building

You'll need Coffeescript to build

npm install -g coffee-script

Source

This will generate a .js from the source

cake build

Docs

Dependencies: Coffeescript & Docco

You'll also need docco to build the docs

npm install -g docco

Building

cake docs

backbone-autocomplete's People

Contributors

chrisabrams avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.