• This repository has been archived on 27/Nov/2018
  • Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    JavaScript
  • Created over 13 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AutoComplete plugin with smart defaults and flexibility to customize

jQuery Smart Auto Complete plugin

Requirements

jQuery 1.5 or above

Usage

In the header section of your page, add two script tags referencing to core jQuery and smart autocomplete plugin. It should look similar to code below:

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.smart_autocomplete.js" type="text/javascript"></script>

To activate the plugin call smartAutoComplete method with options on target jQuery object.

<script type="text/javascript">
$(function(){

 $(target).smartAutoComplete({options})

});
</script>

Options

minCharLimit (integer)

default: 1

Sets the minimum characters user have to type before invoking the autocomplete

maxCharLimit (integer)

default: unlimited

Sets the maximum character range auto-complete will offer suggestions. Useful in free-form fields.

maxResults (integer)

default: null (means unlimited)

Sets the maximum number of results to return.

delay (integer)

default: 0

Sets the number of miliseconds plugin should wait, before calling the filter function.

disabled (boolean)

default: false

Sets whether autocomplete is disabled on the field.

forceSelect (boolean)

default: false

If set to true, field will be always filled with best matching result, without leaving the custom input. Better to enable this option, if you want autocomplete field to behave similar to a HTML select field. (Check Example 2 in the demo)

typeAhead (boolean)

default: false

If set to true, it will offer the best matching result in grey within the field; that can be auto-completed by pressing the right arrow-key or enter. This is similar to behaviour in Google Instant Search's query field (Check Example 3 in the demo)

source (string/array)

Defines the list of items to be filtered. You can give a hardcoded array or a string containing a URL, which will return a JSON array, as the source.

Note: Your can omit this option or provide a different object, if you are defining your own filter method.

filter (function)

parameters available: term, source

Define a custom function that would return the matching items for the term (this will override the default filtering algorithm) Function should return an array or a Deferred object (ajax call)

resultFormatter (function)

parameters available: result

The function you supply here will be called to format the output of an individual result. Function should return a string

resultsContainer (selector)

Define to which element(s) the results should be appended.

resultElement (selector)

References the result elements collection. It should be a jQuery selector which could capture all result elements within the results container (e.g. li, div.result).

Events

Following custom events will be available to the element which has smartAutoComplete activated. You can bind handlers to these events like other jQuery events and also cancel the default handler by calling event.preventDefault().

Note: Make sure you bind the handlers, only after smartAutoComplete is activated on the field. Otherwise context data could get overriden.

To learn more about the default behaviour of the events, please refer to the specs at spec/core/jquery.smart_autocomplete_spec.js.

keyIn

parameters: query

Fires when user type something in the field

resultsReady

parameters: results

Fires when results are ready (returned from the filter function)

showResults

parameters: results

Fires after results are added to the results container

noResults

Fires if filter function returned no results

lostFocus

Fires when autocomplete field loses focus by user clicking outside of the field or focusing on another field. Also, this event is fired when a value is selected

itemSelect

paramters: item

Fires when user selects an item from the result list

itemFocus

paramters: item

Fires when user focuses on an item in results list with mouse or arrow keys

itemUnfocus

paramters: item

Fires when an item in results list looses focus

Styling

Following classes will be used to reference elements added by jQuery Smart Autocomplete plugin.

smart_autocomplete_container - A ul element containing the results.

smart_autocomplete_highlight - This class will be added to a result element when it's focused.

smart_autocomplete_type_ahead_field - If typeAhead option is enabled, additional field will be added behind the autocomplete enabled text field.

Learn More

Introducing jQuery Smart AutoComplete

Demo

Basic Examples

GitHub Instant Search Example

Copyright (c) 2011 Lakshan Perera (laktek.com)

Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) licenses.

More Repositories

1

punch

A fun and easy way to build modern websites
JavaScript
1,173
star
2

realie

Real-time collaborative code editor
JavaScript
387
star
3

extract-values

A simple helper to extract values from a string based on a pattern.
JavaScript
306
star
4

really-simple-color-picker

Simple Color Picker written in jQuery.
JavaScript
179
star
5

distraction-free-writing-vim

Collection of configurations I use to for my distraction free editing environment in Vim
Vim Script
86
star
6

Web-Socket-Examples

Ruby Server to serve web socket requests (based on Event Machine and Thin HTTP parser)
C
69
star
7

punch-blog

A boilerplate to create personal blogs based on Punch
CSS
45
star
8

SugarlessJS

A Functional & Context Oriented way to write JavaScript
JavaScript
43
star
9

Stack-on-Go

Go wrapper for Stack Exchange API
Go
41
star
10

punch-presenter

Create Quick HTML5 Presentations with Punch
JavaScript
25
star
11

todo

Simple command-line todo list manager
Ruby
21
star
12

uniswap-v3-pools

A UI to manage Uniswap v3 pools
TypeScript
13
star
13

favtweets

Sample Punch application that shows favorite tweets of a user
JavaScript
9
star
14

punch-blog-content-handler

A special content handler to manage a blog with Punch.
JavaScript
8
star
15

punch-stylus-compiler

Use Stylus in your Punch projects
JavaScript
8
star
16

punch-sitemap-generator

Plugin to create the sitemap.xml for your Punch sites.
JavaScript
8
star
17

punch-engine-handlebars

Use Handlebars as the template engine in Punch
JavaScript
7
star
18

punch-thirdparty-snippets-helper

Collection of third party snippets (Google Analytics, Disqus, Tweet Button & Web Font Loader), you can easily add to your Punch templates.
JavaScript
7
star
19

punch-sftp-publisher

Publish your site to any host that supports SFTP
JavaScript
6
star
20

laktek.com

Punch based project for laktek.com
HTML
6
star
21

screen-rip-open

An open-source version of screen.rip (unmaintained)
TypeScript
5
star
22

punch-sass-compiler

Use Sass in your Punch projects
JavaScript
5
star
23

LakTEK-blog

Jekyll based engine used to generate laktek.com (as of 24 Nov 2012, laktek.com is generated with Punch. Check github.com/laktek/laktek.com)
JavaScript
5
star
24

contact-form

Simple contact form made with Merb & DataMapper.
Ruby
4
star
25

simple-menu

Full Flexibile menu helper for Rails apps. Supports current tab highlighting, muliple menus and conditional tabs
Ruby
4
star
26

punch2

TypeScript
4
star
27

vspark-mqtt-sample

Go
3
star
28

ssh2-chromeify

Fork of SSH2 client node module using Chrome's Socket API
JavaScript
3
star
29

Sticky-List

A Simple List management app, which is below 5KB (Using HTML5 localStorage)
Ruby
3
star
30

Realie--Deprecated-

Real-time collaborative code editor
Ruby
3
star
31

punch-current-page-helper

Simple helper that adds "current" class to a link if it points to the current page.
JavaScript
3
star
32

tweeps

Simple Sinatra based app that test your knoweldge on your tweeps
3
star
33

punch-engine-jade

Use Jade as the template engine in Punch
JavaScript
2
star
34

requestbin-replay

Replay HTTP requests captured by Requestb.in to another server (useful to test webhooks locally)
JavaScript
2
star
35

dotfiles

Personal dotfiles collection
Vim Script
2
star
36

google4r-checkout

Fork of google4r-checkout
Ruby
2
star
37

ruby-for-fun-and-profit

My simple tutorial series on Ruby for beginners
Ruby
2
star
38

page-rest-open

Code for Page.REST
TypeScript
2
star
39

Aloha-Plugin-Numerated-Headers

Automatic numerated headers for Aloha Editor
JavaScript
2
star
40

reading-list

Simple site to share your favorite books (created with Punch)
2
star
41

Visual-Search

Visual search app for mobile (Symbian S60) using Hornetseye based Server
JavaScript
1
star
42

Battleships

Command line Battleships game done in Ruby
Ruby
1
star
43

punch-simple-markdown-content-handler

Directly use Markdown files for content without JSON or extended directories
JavaScript
1
star
44

litcoffee-content-handler

Literate Coffee Script Content Handler for Punch
JavaScript
1
star
45

ubuntu-chef-solo-puppet

Shell
1
star
46

punch-plugin-template

Grunt template for creating Punch plugins
JavaScript
1
star