Giter VIP home page Giter VIP logo

auto_complete_jquery's Introduction

This plugin provides a auto-complete method for your controllers to be used
with Dylan Verheul's jquery autocomplete plugin.  This jQuery plugin is not
included, and can be obtained from:

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

This auto_complete_jquery plugin is just a modified version of the standard
Rails auto_complete plugin.  It provides the same auto_complete_for method
for your controllers, but eliminates the various view helper methods, as
those are not needed when using jQuery and Unobtrusive JavaScript.

To use this, you need to have jQuery and the autocomplete plugin mentioned 
above (as well as appropriate CSS).  Then, there are four aspects of setting 
up an auto-complete field:

1) Create the text field in your view, which is just a regular form text
field as you'd create in a Rails erb view:

  <%= post.text_field :title, :autocomplete =>"off" %>
  
2) Include the appropriate JS files and CSS in your layout or similar:

  <%= stylesheet_link_tag 'jquery.ui.autocomplete' %>
  <%= javascript_include_tag 'jquery.min', 'jquery.dimensions.min', 'jquery.templating', 'jquery.ui.autocomplete.ext', 'jquery.ui.autocomplete', :cache => 'jquery' %>

3) Use the auto_complete_for controller macro to generate the appropriate
auto-complete method in your controller, such as:

  # Controller
  class BlogController < ApplicationController
    auto_complete_for :post, :title
  end

4) Hook up the text field's autocomplete event in your JavaScript file
using jQuery and the jquery-autocomplete plugin mechanism, for example:

  $(document).ready(function() {
    $("input#post_title").autocomplete("auto_complete_for_post_title")
  });

By default, auto_complete_for limits the results to 10 entries,
and sorts by the given field.

auto_complete_for takes a third parameter, an options hash to
the find method used to search for the records:

  auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'

For more information, see:
* jQuery site: http://jquery.com
* Dylan Verheul jquery autocomplete plugin site: http://www.dyve.net/jquery/?autocomplete
* Good article on jQuery and Rails (note this mentions a different jquery autocomplete 
  plugin, which was originally used in this plugin): http://errtheblog.com/posts/73-the-jskinny-on-jquery
* Original Rails auto_complete plugin: http://github.com/rails/auto_complete


Copyright (c) 2008 Cobalt Edge LLC, released under the MIT license.

auto_complete_jquery's People

Contributors

chris avatar idris avatar

Stargazers

Angus H. avatar Rachel Jaro avatar

Watchers

Rachel Jaro 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.