boussou / searchbox

A live search plugin for jQuery.

Home Page:http://rpheath.com/posts/413-searchbox-jquery-live-search-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Searchbox

This is a jQuery plugin that turns any textbox into a live search, or a “searchbox”.
For previous documentation, see below

ADDED JSON response handling & multiple input fields handling & processing through jquery tmpl

(http://ejohn.org/blog/javascript-micro-templating/ & one of its forks like https://github.com/BorisMoore/jquery-tmpl)

changes: data & tmpl
- data : jquery selector for collecting data to submit
- tmpl : if you use the john resig tmpl, & the server returns back JSON, then it is evaluated for every row
now you can call it like this:


$(‘input.search’).searchbox({
url: your_url,
param: ‘q’,
dom_id: ‘#resultTable’,
delay: 250,
data: ‘input.search’,
tmpl: ‘ ${brand} ${model} ’
})

if you have inputs like this:

    <input type=“text” id=brand class=“form-control search”>
<input type=“text” id=model class=“form-control search”>

then you will receive on the server a GET request with values as: brand=value&model=value
all of the inputs that have a class as defined by the ‘data’ parameter will be included.

so you can have multiple fields & still use a live search form

To allow search to be triggered

You can do it using

$.searchbox.process();

Usage

$('input.search').searchbox()

That’s it, really. There are a few configuration options:

  • url – a GET request is sent to this url (default: ‘/search’)
  • param – the actually parameter that gets sent to the server (default: ‘query’)
  • dom_id – the element that gets updated with the results (default: ‘#results’)
  • delay – the keystroke delay (default: 100 ms)
  • loading_css – the css for an ajax spinner/loading bar (default: ‘#loading’)

So, customizing each config option might look like this:

$('input.search').searchbox({
  url: '/your/search/url',
  param: 'q',
  dom_id: '#thumbnails',
  delay: 250,
  loading_css: '#spinner'
})

Hooks

There are a few places you can hook into the plugin by binding a function to specific events. Here are the events:

  • init.searchbox – triggered once when the plugin code executes
  • before.searchbox – triggered right before the search is performed
  • after.searchbox – triggered right after the search completes

Here’s an example of how to make use of them:

$(document).bind('init.searchbox', function() { ... })

License

© 2009 Ryan Heath, released under the MIT license

About

A live search plugin for jQuery.

http://rpheath.com/posts/413-searchbox-jquery-live-search-plugin


Languages

Language:JavaScript 100.0%