Giter Site home page Giter Site logo

teddygavi / jquery-livesearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from samuelcole/jquery-livesearch

0.0 0.0 0.0 235 KB

Basic tools for an autocomplete or filtering selections with an input over AJAX.

Home Page: http://samuelcole.github.com/jQuery-LiveSearch/

License: MIT License

JavaScript 98.46% CSS 1.06% HTML 0.48%

jquery-livesearch's Introduction

jQuery-LiveSearch

A small engine that returns results when you stop typing into an input field.

jQuery-LiveSearch attaches to an input:

$('input.livesearch').livesearch(options);

Then when a user stops typing, it serializes the nearest parent form and submits it with ajax. When the results come back it fires a custom jquery event:

$elem.trigger('livesearch:results', [data]);

You can bind to that on the input, or any of it's parent elements (bubbling rules!), and then present it to your users in any way you wish.

Options

  • delay: number of milliseconds to wait after a keystroke, before sending a request (default: 400)
  • minimum_characters: don't send a request until the user has typed in this number of characters (default: 3)
  • serialize: the form to serialize and submit (default: $(element).closest('form'))
  • client_side_cache: if set to true, when the user types in something they have already typed in before, jQuery-LiveSearch will use the last results it has obtained (default: true)
  • process_data: function to process form data, before making the AJAX call; should accept and return data as query string (default: false)
  • dataType: data type to pass to jQuery.ajax() call (default: 'json')

Bonus features

  • If the user starts typing before a request is complete, it cancels the original request and starts a new one.
  • If the user types in something they have already typed in before, it uses the last results it has obtained (client_side_cache: true).
  • If the user hits enter before they have 'stopped typing' it sends the request immediately (but you have to block the form from submitting yourself).

Some possible uses

  1. Autocomplete for search: you want to help your users out by making some guesses as to what they are typing.
  2. Selecting an item from a large set: you want to let your user search through a large set of items, and then pick one.
  3. Searching for a page to navigate to: you have a long list of pages that your user might want to visit, but you don't have space (and you're users don't have the patience) to output a long list of links.

Examples

I've started writing some example plugins, that sit on top of the livesearch plugin, the first of this is livesearch.input_dropdown. It takes a JSON array of strings, and creates a div with a class of 'results' with a ul of those strings. It lets you click on, or arrow through, those results, and populates the input with the value of the currently selected value. This is a very basic style for livesearch, and should get you started.

Authors


jquery-livesearch's People

Contributors

samuelcole avatar kewlar 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.