rails3-jquery-autocomplete 0.4.0 → 0.5.0
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/README.markdown
CHANGED
|
@@ -4,6 +4,8 @@ An easy way to use jQuery's autocomplete with Rails 3.
|
|
|
4
4
|
|
|
5
5
|
In now supports both ActiveRecord and [mongoid](http://github.com/mongoid/mongoid).
|
|
6
6
|
|
|
7
|
+
It also supports [Formtastic](http://github.com/justinfrench/formtastic)
|
|
8
|
+
|
|
7
9
|
## ActiveRecord
|
|
8
10
|
|
|
9
11
|
You can find a [detailed example](http://github.com/crowdint/rails3-jquery-autocomplete-app)
|
|
@@ -12,7 +14,7 @@ on how to use this gem with ActiveRecord [here](http://github.com/crowdint/rails
|
|
|
12
14
|
## MongoID
|
|
13
15
|
|
|
14
16
|
You can find a [detailed example](http://github.com/crowdint/rails3-jquery-autocomplete-app/tree/mongoid)
|
|
15
|
-
on how to use this gem with MongoID [here](http://github.com/crowdint/rails3-jquery-autocomplete-app/tree/mongoid).
|
|
17
|
+
on how to use this gem with MongoID [here](http://github.com/crowdint/rails3-jquery-autocomplete-app/tree/mongoid). (Same thing, different branch)
|
|
16
18
|
|
|
17
19
|
## Before you start
|
|
18
20
|
|
|
@@ -154,6 +156,16 @@ If you need to use the id of the selected object, you can use the *:id_element*
|
|
|
154
156
|
|
|
155
157
|
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.
|
|
156
158
|
|
|
159
|
+
## Formtastic
|
|
160
|
+
|
|
161
|
+
If you are using [Formtastic](http://github.com/justinfrench/formtastic), you automatically get the *autocompleted_input* helper on *semantic_form_for*:
|
|
162
|
+
|
|
163
|
+
semantic_form_for @product do |f|
|
|
164
|
+
f.autocompleted_input :brand_name, :url => autocomplete_brand_name_path
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
The only difference with the original helper is that you must specify the autocomplete url using the *:url* option.
|
|
168
|
+
|
|
157
169
|
# Cucumber
|
|
158
170
|
|
|
159
171
|
I have created a step to test your autocomplete with Cucumber and Capybara, all you have to do is add the following lines to your *env.rb* file:
|
|
@@ -192,10 +204,14 @@ And then, install all your dependencies:
|
|
|
192
204
|
|
|
193
205
|
## Running the test suite
|
|
194
206
|
|
|
207
|
+
You need to have an instance of MongoDB running on your computer or all the mongo tests will fail miserably.
|
|
208
|
+
|
|
195
209
|
rake test
|
|
196
|
-
|
|
210
|
+
|
|
197
211
|
# Changelog
|
|
198
212
|
|
|
213
|
+
* 0.5.0 Formtastic support
|
|
214
|
+
* 0.4.0 MongoID support
|
|
199
215
|
* 0.3.6 Using .live() to put autocomplete on dynamic fields
|
|
200
216
|
|
|
201
217
|
# About the Author
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
require 'rails3-jquery-autocomplete/form_helper'
|
|
2
2
|
require 'rails3-jquery-autocomplete/helpers'
|
|
3
3
|
require 'rails3-jquery-autocomplete/autocomplete'
|
|
4
|
+
require 'rails3-jquery-autocomplete/formtastic_plugin'
|
|
4
5
|
|
|
5
6
|
class ActionController::Base
|
|
6
7
|
extend Rails3JQueryAutocomplete::ClassMethods
|
|
7
8
|
include Rails3JQueryAutocomplete::Helpers
|
|
8
9
|
end
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# Load the formtastic plugin if using Formtastic
|
|
13
|
+
#
|
|
14
|
+
begin
|
|
15
|
+
require 'formtastic'
|
|
16
|
+
class Formtastic::SemanticFormBuilder < ActionView::Helpers::FormBuilder
|
|
17
|
+
include Rails3JQueryAutocomplete::FormtasticPlugin
|
|
18
|
+
end
|
|
19
|
+
rescue LoadError
|
|
20
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Rails3JQueryAutocomplete
|
|
2
|
+
module FormtasticPlugin
|
|
3
|
+
def autocompleted_input(method, options = {})
|
|
4
|
+
if options.key?(:selected) || options.key?(:checked) || options.key?(:default)
|
|
5
|
+
::ActiveSupport::Deprecation.warn(
|
|
6
|
+
"The :selected, :checked (and :default) options are deprecated in Formtastic and will be removed from 1.0. " <<
|
|
7
|
+
"Please set default values in your models (using an after_initialize callback) or in your controller set-up. " <<
|
|
8
|
+
"See http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html for more information.", caller)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
options[:required] = method_required?(method) unless options.key?(:required)
|
|
12
|
+
options[:as] ||= "autocompleted_string"
|
|
13
|
+
|
|
14
|
+
html_class = [ options[:as], (options[:required] ? :required : :optional) ]
|
|
15
|
+
html_class << 'error' if @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?
|
|
16
|
+
|
|
17
|
+
wrapper_html = options.delete(:wrapper_html) || {}
|
|
18
|
+
wrapper_html[:id] ||= generate_html_id(method)
|
|
19
|
+
wrapper_html[:class] = (html_class << wrapper_html[:class]).flatten.compact.join(' ')
|
|
20
|
+
|
|
21
|
+
if options[:input_html] && options[:input_html][:id]
|
|
22
|
+
options[:label_html] ||= {}
|
|
23
|
+
options[:label_html][:for] ||= options[:input_html][:id]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
input_parts = self.class.inline_order.dup
|
|
27
|
+
input_parts = input_parts - [:errors, :hints] if options[:as] == :hidden
|
|
28
|
+
|
|
29
|
+
list_item_content = input_parts.map do |type|
|
|
30
|
+
send(:"inline_#{type}_for", method, options)
|
|
31
|
+
end.compact.join("\n")
|
|
32
|
+
|
|
33
|
+
return template.content_tag(:li, Formtastic::Util.html_safe(list_item_content), wrapper_html)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
protected
|
|
38
|
+
def autocompleted_string_input(method, options)
|
|
39
|
+
self.label(method, options_for_label(options)) << autocomplete_field(method, options.delete(:url), options)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
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: 11
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 5
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.5.0
|
|
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-10-
|
|
18
|
+
date: 2010-10-26 00:00:00 -05:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -52,6 +52,7 @@ files:
|
|
|
52
52
|
- lib/rails3-jquery-autocomplete.rb
|
|
53
53
|
- lib/rails3-jquery-autocomplete/autocomplete.rb
|
|
54
54
|
- lib/rails3-jquery-autocomplete/form_helper.rb
|
|
55
|
+
- lib/rails3-jquery-autocomplete/formtastic_plugin.rb
|
|
55
56
|
- lib/rails3-jquery-autocomplete/helpers.rb
|
|
56
57
|
- test/active_record_controller_test.rb
|
|
57
58
|
- test/form_helper_test.rb
|