You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

autocomplete_select

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autocomplete_select

0.1.0
Rubygems
Version published
Maintainers
2
Created
Source

autocomplete_select

Build Status Coverage Status

Integrate with jQuery UI autocomplete library to provide select by autocomplete input and form helper.

Installation

Add this line to your application's Gemfile:

gem 'autocomplete_select'

And then execute:

bundle

Or install it yourself as:

gem install autocomplete_select

Usage

Require Javascript

Make sure you required jQuery, jQuery UI and add the following to /app/assets/javascripts/application.js:

//= require autocomplete_select

Require CSS

Make sure you required jQuery UI css.

Controller

You have to implement a controller and action like this

class UsersController < ActionController::Base
  def search
    term = params[:term]
    users = User.where("name LIKE ?", "%#{term}%")
    render :json => users.map{ |user| {:value => user.id, :label => user.name}}
  end
end

The input term is what you type in textbox. The output must be an array with value and label.

Helpers

You can use autocomplete_select_tag and autocomplete_select.

<%= autocomplete_select_tag(name, search_path, value, autocomplete_options, html_options) %>
<%= autocomplete_select_tag(name, search_path, value, display, autocomplete_options, html_options) %>
<%= autocomplete_select_tag(:user_id, search_users_path, 1, 'username', {:minLength => 3}, {:class => 'user'}) %>
<%= autocomplete_select_tag(:user_id, search_users_path, 1, 'username') %>
<%= autocomplete_select_tag(:user_id, search_users_path) %>

or form builder

<% form_for @item do |f| %>
<%= f.autocomplete_select(method, search_path, autocomplete_options, html_options) %>
<%= f.autocomplete_select(method, search_path, display, autocomplete_options, html_options) %>
<%= f.autocomplete_select(:user_id, search_users_path, 'username', {:minLength => 3}, {:class => 'user'}) %>
<%= f.autocomplete_select(:user_id, search_users_path, 'username') %>
<%= f.autocomplete_select(:user_id, search_users_path) %>
<% end %>

License

The gem is available as open source under the terms of the MIT License.

Contact

The project's website is located at https://github.com/emn178/autocomplete_select
Author: Chen, Yi-Cyuan (emn178@gmail.com)

FAQs

Package last updated on 26 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts