rails3-jquery-autocomplete 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -4
- data/lib/form_helper.rb +29 -0
- data/lib/generators/templates/autocomplete-rails.js +1 -0
- data/test/form_helper_test.rb +16 -2
- metadata +4 -4
data/README.markdown
CHANGED
@@ -116,12 +116,12 @@ This wouldn't really make much sense unless you use it with the :id_element HTML
|
|
116
116
|
On your view, all you have to do is include the attribute autocomplete on the text field
|
117
117
|
using the url to the autocomplete action as the value.
|
118
118
|
form_for @product do |f|
|
119
|
-
f.
|
119
|
+
f.autocomplete_field :brand_name, autocomplete_brand_name_products_path
|
120
120
|
end
|
121
121
|
|
122
122
|
This will generate an HTML tag that looks like:
|
123
123
|
|
124
|
-
<input type="text" autocomplete="products/autocomplete_brand_name">
|
124
|
+
<input type="text" data-autocomplete="products/autocomplete_brand_name">
|
125
125
|
|
126
126
|
Now your autocomplete JS code is unobtrusive, Rails 3 style.
|
127
127
|
|
@@ -129,7 +129,7 @@ Now your autocomplete JS code is unobtrusive, Rails 3 style.
|
|
129
129
|
|
130
130
|
If you need to use the id of the selected object, you can use the *:id_element* HTML tag too:
|
131
131
|
|
132
|
-
f.
|
132
|
+
f.autocomplete_field :brand_name, autocomplete_brand_name_products_path, :id_element => '#some_element'
|
133
133
|
|
134
134
|
This will update the field with id *#some_element with the id of the selected object. The value for this option can be any jQuery selector.
|
135
135
|
|
@@ -137,7 +137,7 @@ This will update the field with id *#some_element with the id of the selected ob
|
|
137
137
|
|
138
138
|
If you want to make changes to the gem, first install bundler 1.0.0:
|
139
139
|
|
140
|
-
gem install bundler
|
140
|
+
gem install bundler
|
141
141
|
|
142
142
|
And then, install all your dependencies:
|
143
143
|
|
data/lib/form_helper.rb
CHANGED
@@ -5,6 +5,18 @@ module ActionView
|
|
5
5
|
def text_field(object_name, method, options = {})
|
6
6
|
original_text_field(object_name, method, rename_autocomplete_option(options))
|
7
7
|
end
|
8
|
+
|
9
|
+
# Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by +method+) and
|
10
|
+
# that is populated with jQuery's autocomplete plugin.
|
11
|
+
#
|
12
|
+
# ==== Examples
|
13
|
+
# autocomplete_field(:post, :title, author_autocomplete_path, :size => 20)
|
14
|
+
# # => <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" data-autocomplete="author/autocomplete"/>
|
15
|
+
#
|
16
|
+
def autocomplete_field(object_name, method, source, options ={})
|
17
|
+
options[:autocomplete] = source
|
18
|
+
text_field(object_name, method, options)
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
module FormTagHelper
|
@@ -12,6 +24,17 @@ module ActionView
|
|
12
24
|
def text_field_tag(name, value = nil, options = {})
|
13
25
|
original_text_field_tag(name, value, rename_autocomplete_option(options))
|
14
26
|
end
|
27
|
+
|
28
|
+
# Creates a standard text field that can be populated with jQuery's autocomplete plugin
|
29
|
+
#
|
30
|
+
# ==== Examples
|
31
|
+
# autocomplete_field_tag 'address', '', address_autocomplete_path, :size => 75
|
32
|
+
# # => <input id="address" name="address" size="75" type="text" value="" data-autocomplete="address/autocomplete"/>
|
33
|
+
#
|
34
|
+
def autocomplete_field_tag(name, value, source, options ={})
|
35
|
+
options[:autocomplete] = source
|
36
|
+
text_field_tag(name, value, options)
|
37
|
+
end
|
15
38
|
end
|
16
39
|
|
17
40
|
#
|
@@ -24,4 +47,10 @@ module ActionView
|
|
24
47
|
options
|
25
48
|
end
|
26
49
|
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ActionView::Helpers::FormBuilder #:nodoc:
|
53
|
+
def autocomplete_field(method, options)
|
54
|
+
@template.autocomplete_field(@object_name, method, options)
|
55
|
+
end
|
27
56
|
end
|
data/test/form_helper_test.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
+
class Post
|
4
|
+
attr_accessor :author
|
5
|
+
end
|
6
|
+
|
3
7
|
class FormHelperTest < ActionView::TestCase
|
4
8
|
def test_text_field_tag
|
5
9
|
assert_match(/data-autocomplete=\"some\/path\"/, text_field_tag('field_name', '', :autocomplete => 'some/path'))
|
6
10
|
end
|
7
|
-
|
11
|
+
|
8
12
|
def test_text_field
|
9
|
-
|
13
|
+
post = Post.new
|
14
|
+
assert_match(/data-autocomplete=\"some\/path\"/, text_field(:post, :author, :autocomplete => 'some/path'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_autocomplete_field_tag
|
18
|
+
assert_match(/data-autocomplete=\"some\/path\"/, autocomplete_field_tag('field_name', '', 'some/path'))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_autocomplete_field
|
22
|
+
post= Post.new
|
23
|
+
assert_match(/data-autocomplete=\"some\/path\"/, autocomplete_field(:post, :author, 'some/path'))
|
10
24
|
end
|
11
25
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-jquery-autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Padilla
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|