Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQuery autocomplete

Rails Auto Completion plugin using jQuery-UI1 widget; it works similarly to the original rails auto complete, but generating unobtrusive javascript. Additional features:

  • named scope items filtering, based on a customized list of autocomplete options.

WARNING NOTE: This is an active work in progress – currently only used on few live projects right now. Use at your own discretion.

Usage example

In the controller you can use the macro function as such

class ExampleController < ApplicationController
    auto_complete_for :fruit, :name
    ...
end

In your views:

<%= text_field_with_auto_complete :fruit, :name %>

be sure to include the jquery/jquery-ui javascript in your layout:

<%= javascript_include_tag 'jquery, 'jquery-ui.min', 'jquery-ui-i18n.min' %>

Named scopes with auto_complete_for:

auto_complete_for now optionally accepts a block that is called with the item list and HTTP parameters when the auto complete AJAX request is received. This block can be used to specify that a named scope be used to generate a customized list of autocomplete options.

Example using anonymous scope:

auto_complete_for :fruit, :shape do |items, params|
  items.scoped( { :conditions => [ "colour = ?", params['fruit']['color'] ] })
end

Example using named scope:

Having the model:

class Fruit < ActiveRecord::Base
  belongs_to :owner
  named_scope :by_owner,
    lambda { |owner_name| {
      :include => :owner,
      :conditions => [ "owner.name = ?", owner_name ]
    } }
end

In the controller you can use the macro function as such

auto_complete_for :fruit, :name do | items, params |
  items.by_owner(params['owner'])
end

Todo

  • test, test… test!

Found a Bug?

Please direct all queries to the issue tracker: http://github.com/michelefranzin/jquery_autocomplete/issues

Credits

Thanks to Paul Smith for the original idea and Pat Shaughnessy for inspirating me the named scope part.

References

1 jQuery-UI

Copyright

Copyright © 2010 Michele Franzin. See LICENSE for details.

About

Rails plugin to give support for autocomplete fields using jQuery-UI autocomplete widget

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.