rails3-jquery-autocomplete-moc 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/form_helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormHelper
|
4
|
+
alias_method :original_text_field, :text_field
|
5
|
+
def text_field(object_name, method, options = {})
|
6
|
+
original_text_field(object_name, method, rename_autocomplete_option(options))
|
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
|
20
|
+
end
|
21
|
+
|
22
|
+
module FormTagHelper
|
23
|
+
alias_method :original_text_field_tag, :text_field_tag
|
24
|
+
def text_field_tag(name, value = nil, options = {})
|
25
|
+
original_text_field_tag(name, value, rename_autocomplete_option(options))
|
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
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Method used to rename the autocomplete key to a more standard
|
42
|
+
# data-autocomplete key
|
43
|
+
#
|
44
|
+
private
|
45
|
+
def rename_autocomplete_option(options)
|
46
|
+
options["data-autocomplete"] = options.delete(:autocomplete)
|
47
|
+
options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ActionView::Helpers::FormBuilder #:nodoc:
|
53
|
+
def autocomplete_field(method, source, options = {})
|
54
|
+
@template.autocomplete_field(@object_name, method, source, options)
|
55
|
+
end
|
56
|
+
end
|
@@ -15,13 +15,18 @@
|
|
15
15
|
*/
|
16
16
|
|
17
17
|
$(document).ready(function(){
|
18
|
-
$('input[autocomplete]').each(function(i){
|
18
|
+
$('input[data-autocomplete]').each(function(i){
|
19
19
|
$(this).autocomplete({
|
20
|
-
source: $(this).attr('autocomplete'),
|
20
|
+
source: $(this).attr('data-autocomplete'),
|
21
21
|
select: function(event, ui) {
|
22
|
-
|
22
|
+
$(this).val(ui.item.value);
|
23
|
+
if ($(this).attr('id_element')) {
|
23
24
|
$($(this).attr('id_element')).val(ui.item.id);
|
24
25
|
}
|
26
|
+
|
27
|
+
if($(this).attr('label_element')) {
|
28
|
+
$($(this).attr('label_element')).val(ui.item.value);
|
29
|
+
}
|
25
30
|
return false;
|
26
31
|
}
|
27
32
|
});
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails3-jquery-autocomplete-moc}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["doug schlenker"]
|
@@ -25,12 +25,14 @@ Gem::Specification.new do |s|
|
|
25
25
|
"README.markdown",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
|
+
"lib/form_helper.rb",
|
28
29
|
"lib/generators/autocomplete_generator.rb",
|
29
30
|
"lib/generators/templates/autocomplete-rails.js",
|
30
31
|
"lib/rails3-jquery-autocomplete-moc.rb",
|
31
32
|
"rails3-jquery-autocomplete-moc.gemspec",
|
32
33
|
"test/autocomplete_generator_test.rb",
|
33
34
|
"test/controller_module_test.rb",
|
35
|
+
"test/form_helper_test.rb",
|
34
36
|
"test/test_helper.rb"
|
35
37
|
]
|
36
38
|
s.homepage = %q{http://github.com/adeviadoug/rails3-jquery-autocomplete-moc}
|
@@ -40,7 +42,8 @@ Gem::Specification.new do |s|
|
|
40
42
|
s.rubygems_version = %q{1.3.7}
|
41
43
|
s.summary = %q{Adaptation of rails3-jquery-autocomplete}
|
42
44
|
s.test_files = [
|
43
|
-
"test/
|
45
|
+
"test/form_helper_test.rb",
|
46
|
+
"test/test_helper.rb",
|
44
47
|
"test/autocomplete_generator_test.rb",
|
45
48
|
"test/controller_module_test.rb"
|
46
49
|
]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Post
|
4
|
+
attr_accessor :author
|
5
|
+
end
|
6
|
+
|
7
|
+
class FormHelperTest < ActionView::TestCase
|
8
|
+
def test_text_field_tag
|
9
|
+
assert_match(/data-autocomplete=\"some\/path\"/, text_field_tag('field_name', '', :autocomplete => 'some/path'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_text_field
|
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'))
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-jquery-autocomplete-moc
|
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
|
- doug schlenker
|
@@ -52,12 +52,14 @@ files:
|
|
52
52
|
- README.markdown
|
53
53
|
- Rakefile
|
54
54
|
- VERSION
|
55
|
+
- lib/form_helper.rb
|
55
56
|
- lib/generators/autocomplete_generator.rb
|
56
57
|
- lib/generators/templates/autocomplete-rails.js
|
57
58
|
- lib/rails3-jquery-autocomplete-moc.rb
|
58
59
|
- rails3-jquery-autocomplete-moc.gemspec
|
59
60
|
- test/autocomplete_generator_test.rb
|
60
61
|
- test/controller_module_test.rb
|
62
|
+
- test/form_helper_test.rb
|
61
63
|
- test/test_helper.rb
|
62
64
|
has_rdoc: true
|
63
65
|
homepage: http://github.com/adeviadoug/rails3-jquery-autocomplete-moc
|
@@ -94,6 +96,7 @@ signing_key:
|
|
94
96
|
specification_version: 3
|
95
97
|
summary: Adaptation of rails3-jquery-autocomplete
|
96
98
|
test_files:
|
99
|
+
- test/form_helper_test.rb
|
97
100
|
- test/test_helper.rb
|
98
101
|
- test/autocomplete_generator_test.rb
|
99
102
|
- test/controller_module_test.rb
|