rails3-jquery-autocomplete 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -50,15 +50,7 @@ And include autocomplete-rails.js on your layouts
|
|
50
50
|
|
51
51
|
javascript_include_tag "autocomplete-rails.js"
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
Just add it to your app/assets/javascripts/application.js file
|
56
|
-
|
57
|
-
//= require jquery
|
58
|
-
//= require jquery_ujs
|
59
|
-
//= require autocomplete-rails
|
60
|
-
|
61
|
-
## Upgrading from older versions
|
53
|
+
#### Upgrading from older versions
|
62
54
|
|
63
55
|
If you are upgrading from a previous version, run the generator after installing to replace the javascript file.
|
64
56
|
|
@@ -66,13 +58,22 @@ If you are upgrading from a previous version, run the generator after installing
|
|
66
58
|
|
67
59
|
I'd recommend you do this every time you update to make sure you have the latest JS file.
|
68
60
|
|
69
|
-
|
61
|
+
#### Uncompressed Javascript file
|
70
62
|
|
71
63
|
If you want to make changes to the JS file, you can install the
|
72
64
|
uncompressed version by running:
|
73
65
|
|
74
66
|
rails generate autocomplete:uncompressed
|
75
67
|
|
68
|
+
### Rails 3.1.x
|
69
|
+
|
70
|
+
Just add it to your app/assets/javascripts/application.js file
|
71
|
+
|
72
|
+
//= require jquery
|
73
|
+
//= require jquery_ujs
|
74
|
+
//= require jquery-ui
|
75
|
+
//= require autocomplete-rails
|
76
|
+
|
76
77
|
## Usage
|
77
78
|
|
78
79
|
### Model Example
|
@@ -223,8 +224,8 @@ The previous example would fetch the extra attribute slogan and update jQuery('#
|
|
223
224
|
A javascript event named *railsAutocomplete.select* is fired on the input field when a value is selected from the autocomplete drop down. If you need to do something more complex than update fields with data, you can hook into this event, like so:
|
224
225
|
|
225
226
|
$('#my_autocomplete_field').bind('railsAutocomplete.select', function(event, data){
|
226
|
-
|
227
|
-
|
227
|
+
/* Do something here */
|
228
|
+
alert(data.item.id);
|
228
229
|
});
|
229
230
|
|
230
231
|
## Formtastic
|
@@ -14,10 +14,6 @@
|
|
14
14
|
* <input type="text" data-autocomplete="/url/to/autocomplete" data-id-element="#id_field">
|
15
15
|
*/
|
16
16
|
|
17
|
-
$(document).ready(function(){
|
18
|
-
$('input[data-autocomplete]').railsAutocomplete();
|
19
|
-
});
|
20
|
-
|
21
17
|
(function(jQuery)
|
22
18
|
{
|
23
19
|
var self = null;
|
@@ -41,7 +37,7 @@ $(document).ready(function(){
|
|
41
37
|
jQuery.railsAutocomplete.fn.extend = jQuery.railsAutocomplete.extend = jQuery.extend;
|
42
38
|
jQuery.railsAutocomplete.fn.extend({
|
43
39
|
init: function(e) {
|
44
|
-
e.delimiter =
|
40
|
+
e.delimiter = jQuery(e).attr('data-delimiter') || null;
|
45
41
|
function split( val ) {
|
46
42
|
return val.split( e.delimiter );
|
47
43
|
}
|
@@ -49,15 +45,15 @@ $(document).ready(function(){
|
|
49
45
|
return split( term ).pop().replace(/^\s+/,"");
|
50
46
|
}
|
51
47
|
|
52
|
-
|
48
|
+
jQuery(e).autocomplete({
|
53
49
|
source: function( request, response ) {
|
54
|
-
|
50
|
+
jQuery.getJSON( jQuery(e).attr('data-autocomplete'), {
|
55
51
|
term: extractLast( request.term )
|
56
52
|
}, function() {
|
57
|
-
|
53
|
+
jQuery(arguments[0]).each(function(i, el) {
|
58
54
|
var obj = {};
|
59
55
|
obj[el.id] = el;
|
60
|
-
|
56
|
+
jQuery(e).data(obj);
|
61
57
|
});
|
62
58
|
response.apply(null, arguments);
|
63
59
|
});
|
@@ -85,29 +81,33 @@ $(document).ready(function(){
|
|
85
81
|
this.value = terms.join( e.delimiter );
|
86
82
|
} else {
|
87
83
|
this.value = terms.join("");
|
88
|
-
if (
|
89
|
-
|
84
|
+
if (jQuery(this).attr('data-id-element')) {
|
85
|
+
jQuery(jQuery(this).attr('data-id-element')).val(ui.item.id);
|
90
86
|
}
|
91
|
-
if (
|
92
|
-
var data =
|
93
|
-
var update_elements =
|
87
|
+
if (jQuery(this).attr('data-update-elements')) {
|
88
|
+
var data = jQuery(this).data(ui.item.id.toString());
|
89
|
+
var update_elements = jQuery.parseJSON(jQuery(this).attr("data-update-elements"));
|
94
90
|
for (var key in update_elements) {
|
95
|
-
|
91
|
+
jQuery(update_elements[key]).val(data[key]);
|
96
92
|
}
|
97
93
|
}
|
98
94
|
}
|
99
95
|
var remember_string = this.value;
|
100
|
-
|
101
|
-
if(
|
102
|
-
|
103
|
-
|
96
|
+
jQuery(this).bind('keyup.clearId', function(){
|
97
|
+
if(jQuery(this).val().trim() != remember_string.trim()){
|
98
|
+
jQuery(jQuery(this).attr('data-id-element')).val("");
|
99
|
+
jQuery(this).unbind('keyup.clearId');
|
104
100
|
}
|
105
101
|
});
|
106
|
-
|
102
|
+
jQuery(this).trigger('railsAutocomplete.select', ui);
|
107
103
|
|
108
104
|
return false;
|
109
105
|
}
|
110
106
|
});
|
111
107
|
}
|
112
108
|
});
|
109
|
+
|
110
|
+
jQuery(document).ready(function(){
|
111
|
+
jQuery('input[data-autocomplete]').railsAutocomplete();
|
112
|
+
});
|
113
113
|
})(jQuery);
|
@@ -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
|
-
|
16
|
+
(function(a){var b=null;a.fn.railsAutocomplete=function(){return this.live("focus",function(){this.railsAutoCompleter||(this.railsAutoCompleter=new a.railsAutocomplete(this))})},a.railsAutocomplete=function(a){_e=a,this.init(_e)},a.railsAutocomplete.fn=a.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"},a.railsAutocomplete.fn.extend=a.railsAutocomplete.extend=a.extend,a.railsAutocomplete.fn.extend({init:function(b){function c(a){return a.split(b.delimiter)}function d(a){return c(a).pop().replace(/^\s+/,"")}b.delimiter=a(b).attr("data-delimiter")||null,a(b).autocomplete({source:function(c,f){a.getJSON(a(b).attr("data-autocomplete"),{term:d(c.term)},function(){a(arguments[0]).each(function(c,d){var f={};f[d.id]=d,a(b).data(f)}),f.apply(null,arguments)})},search:function(){var a=d(this.value);if(a.length<2)return!1},focus:function(){return!1},select:function(d,f){var g=c(this.value);g.pop(),g.push(f.item.value);if(b.delimiter!=null)g.push(""),this.value=g.join(b.delimiter);else{this.value=g.join(""),a(this).attr("data-id-element")&&a(a(this).attr("data-id-element")).val(f.item.id);if(a(this).attr("data-update-elements")){var h=a(this).data(f.item.id.toString()),i=a.parseJSON(a(this).attr("data-update-elements"));for(var j in i)a(i[j]).val(h[j])}}var k=this.value;return a(this).bind("keyup.clearId",function(){a(this).val().trim()!=k.trim()&&(a(a(this).attr("data-id-element")).val(""),a(this).unbind("keyup.clearId"))}),a(this).trigger("railsAutocomplete.select",f),!1}})}}),a(document).ready(function(){a("input[data-autocomplete]").railsAutocomplete()})})(jQuery)
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70221319872760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70221319872760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &70221319872200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70221319872200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mongoid
|
38
|
-
requirement: &
|
38
|
+
requirement: &70221319871460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70221319871460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mongo_mapper
|
49
|
-
requirement: &
|
49
|
+
requirement: &70221319870780 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0.9'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70221319870780
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bson_ext
|
60
|
-
requirement: &
|
60
|
+
requirement: &70221319870180 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.3.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70221319870180
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda
|
71
|
-
requirement: &
|
71
|
+
requirement: &70221319869580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.11.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70221319869580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: uglifier
|
82
|
-
requirement: &
|
82
|
+
requirement: &70221319869060 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70221319869060
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rr
|
93
|
-
requirement: &
|
93
|
+
requirement: &70221319858700 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70221319858700
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rcov
|
104
|
-
requirement: &
|
104
|
+
requirement: &70221319858060 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70221319858060
|
113
113
|
description: Use jQuery's autocomplete plugin with Rails 3.
|
114
114
|
email: david.padilla@crowdint.com
|
115
115
|
executables: []
|