rails3-jquery-autocomplete 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
* 1.0.11
|
4
|
+
* mongoid: escape regular expression in search
|
5
|
+
* When possible, use jQuery .on() rather than .live()
|
3
6
|
* 1.0.6 Postgres or non-postgres queries are now determined at model level
|
4
7
|
* 1.0.3 Fixed Formtastic 2.0 + Ruby 1.8.7 compat issue
|
5
8
|
* 1.0.2 Fixed issue #93, #94
|
data/README.md
CHANGED
@@ -197,6 +197,17 @@ If you are not using a FormBuilder (form_for) or you just want to include an aut
|
|
197
197
|
autocomplete_field_tag 'address', '', address_autocomplete_path, :size => 75
|
198
198
|
end
|
199
199
|
|
200
|
+
#### Multiple Values Separated by Delimiter
|
201
|
+
|
202
|
+
To generate an autocomplete input field that accepts multiple values separated by a given delimiter, add the `'data-delimiter'` and `:multiple` options:
|
203
|
+
|
204
|
+
form_for @product do |f|
|
205
|
+
f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
|
206
|
+
'data-delimiter' => ',', :multiple => true
|
207
|
+
end
|
208
|
+
|
209
|
+
NOTE: Setting the `:multiple` option to `true` will result in the chosen values being submitted as an array. Leaving this option off will result in the values being passed as a single string, with the values separated by your chosen delimiter.
|
210
|
+
|
200
211
|
Now your autocomplete code is unobtrusive, Rails 3 style.
|
201
212
|
|
202
213
|
### Getting the object id
|
@@ -18,11 +18,17 @@
|
|
18
18
|
{
|
19
19
|
var self = null;
|
20
20
|
jQuery.fn.railsAutocomplete = function() {
|
21
|
-
|
21
|
+
var handler = function() {
|
22
22
|
if (!this.railsAutoCompleter) {
|
23
23
|
this.railsAutoCompleter = new jQuery.railsAutocomplete(this);
|
24
24
|
}
|
25
|
-
}
|
25
|
+
};
|
26
|
+
if (jQuery.fn.on !== undefined) {
|
27
|
+
return $(document).on('focus',this.selector,handler);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
return this.live('focus',handler);
|
31
|
+
}
|
26
32
|
};
|
27
33
|
|
28
34
|
jQuery.railsAutocomplete = function (e) {
|
@@ -13,4 +13,4 @@
|
|
13
13
|
* Example:
|
14
14
|
* <input type="text" data-autocomplete="/url/to/autocomplete" data-id-element="#id_field">
|
15
15
|
*/
|
16
|
-
(function(e){var t=null;e.fn.railsAutocomplete=function(){
|
16
|
+
(function(e){var t=null;e.fn.railsAutocomplete=function(){var t=function(){this.railsAutoCompleter||(this.railsAutoCompleter=new e.railsAutocomplete(this))};return e.fn.on!==undefined?$(document).on("focus",this.selector,t):this.live("focus",t)},e.railsAutocomplete=function(e){_e=e,this.init(_e)},e.railsAutocomplete.fn=e.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"},e.railsAutocomplete.fn.extend=e.railsAutocomplete.extend=e.extend,e.railsAutocomplete.fn.extend({init:function(t){function n(e){return e.split(t.delimiter)}function r(e){return n(e).pop().replace(/^\s+/,"")}t.delimiter=e(t).attr("data-delimiter")||null,e(t).autocomplete({source:function(n,i){e.getJSON(e(t).attr("data-autocomplete"),{term:r(n.term)},function(){arguments[0].length==0&&(arguments[0]=[],arguments[0][0]={id:"",label:"no existing match"}),e(arguments[0]).each(function(n,r){var i={};i[r.id]=r,e(t).data(i)}),i.apply(null,arguments)})},change:function(t,n){if(e(e(this).attr("data-id-element")).val()=="")return;e(e(this).attr("data-id-element")).val(n.item?n.item.id:"");var r=e.parseJSON(e(this).attr("data-update-elements")),i=n.item?e(this).data(n.item.id.toString()):{};if(r&&e(r["id"]).val()=="")return;for(var s in r)e(r[s]).val(n.item?i[s]:"")},search:function(){var e=r(this.value);if(e.length<2)return!1},focus:function(){return!1},select:function(r,i){var s=n(this.value);s.pop(),s.push(i.item.value);if(t.delimiter!=null)s.push(""),this.value=s.join(t.delimiter);else{this.value=s.join(""),e(this).attr("data-id-element")&&e(e(this).attr("data-id-element")).val(i.item.id);if(e(this).attr("data-update-elements")){var o=e(this).data(i.item.id.toString()),u=e.parseJSON(e(this).attr("data-update-elements"));for(var a in u)e(u[a]).val(o[a])}}var f=this.value;return e(this).bind("keyup.clearId",function(){e(this).val().trim()!=f.trim()&&(e(e(this).attr("data-id-element")).val(""),e(this).unbind("keyup.clearId"))}),e(t).trigger("railsAutocomplete.select",i),!1}})}}),e(document).ready(function(){e("input[data-autocomplete]").railsAutocomplete()})})(jQuery);
|
@@ -23,9 +23,9 @@ module Rails3JQueryAutocomplete
|
|
23
23
|
order = get_autocomplete_order(method, options)
|
24
24
|
|
25
25
|
if is_full_search
|
26
|
-
search = '.*' + term + '.*'
|
26
|
+
search = '.*' + Regexp.escape(term) + '.*'
|
27
27
|
else
|
28
|
-
search = '^' + term
|
28
|
+
search = '^' + Regexp.escape(term)
|
29
29
|
end
|
30
30
|
items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-jquery-autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -272,7 +272,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
272
272
|
version: '0'
|
273
273
|
segments:
|
274
274
|
- 0
|
275
|
-
hash:
|
275
|
+
hash: 3645478103120310427
|
276
276
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
277
277
|
none: false
|
278
278
|
requirements:
|
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
version: '0'
|
282
282
|
segments:
|
283
283
|
- 0
|
284
|
-
hash:
|
284
|
+
hash: 3645478103120310427
|
285
285
|
requirements: []
|
286
286
|
rubyforge_project:
|
287
287
|
rubygems_version: 1.8.23
|