rails3-jquery-autocomplete 0.6.4 → 0.6.5

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails3-jquery-autocomplete (0.6.4)
4
+ rails3-jquery-autocomplete (0.6.5)
5
5
  rails (~> 3.0.0)
6
6
  yajl-ruby
7
7
 
data/README.markdown CHANGED
@@ -183,6 +183,12 @@ The :update_elements attribute accepts a hash where the keys represent the objec
183
183
 
184
184
  The previous example would fetch the extra attribute slogan and update jQuery('#some_other_element') with the slogan value.
185
185
 
186
+ ### Running custom code on selection
187
+
188
+ 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:
189
+
190
+ $('#my_autocomplete_field').bind('railsAutocomplete.select', function(){ /* Do something here */});
191
+
186
192
  ## Formtastic
187
193
 
188
194
  If you are using [Formtastic](http://github.com/justinfrench/formtastic), you automatically get the *autocompleted_input* helper on *semantic_form_for*:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- rails3-jquery-autocomplete (0.6.4)
4
+ rails3-jquery-autocomplete (0.6.5)
5
5
  rails (~> 3.0.0)
6
6
  yajl-ruby
7
7
 
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * Example:
8
8
  * <input type="text" data-autocomplete="/url/to/autocomplete">
9
- *
9
+ *
10
10
  * Optionally, you can use a jQuery selector to specify a field that can
11
11
  * be updated with the element id whenever you find a matching value
12
12
  *
@@ -28,16 +28,16 @@ $(document).ready(function(){
28
28
  }
29
29
  });
30
30
  };
31
-
31
+
32
32
  jQuery.railsAutocomplete = function (e) {
33
33
  _e = e;
34
34
  this.init(_e);
35
35
  };
36
-
36
+
37
37
  jQuery.railsAutocomplete.fn = jQuery.railsAutocomplete.prototype = {
38
38
  railsAutocomplete: '0.0.1'
39
39
  };
40
-
40
+
41
41
  jQuery.railsAutocomplete.fn.extend = jQuery.railsAutocomplete.extend = jQuery.extend;
42
42
  jQuery.railsAutocomplete.fn.extend({
43
43
  init: function(e) {
@@ -48,12 +48,19 @@ $(document).ready(function(){
48
48
  function extractLast( term ) {
49
49
  return split( term ).pop().replace(/^\s+/,"");
50
50
  }
51
-
51
+
52
52
  $(e).autocomplete({
53
53
  source: function( request, response ) {
54
54
  $.getJSON( $(e).attr('data-autocomplete'), {
55
55
  term: extractLast( request.term )
56
- }, response );
56
+ }, function() {
57
+ $(arguments[0]).each(function(i, el) {
58
+ var obj = {};
59
+ obj[el.id] = el;
60
+ $(e).data(obj);
61
+ });
62
+ response.apply(null, arguments);
63
+ });
57
64
  },
58
65
  search: function() {
59
66
  // custom minLength
@@ -81,8 +88,16 @@ $(document).ready(function(){
81
88
  if ($(this).attr('id_element')) {
82
89
  $($(this).attr('id_element')).val(ui.item.id);
83
90
  }
84
- };
85
-
91
+ if ($(this).attr('data-update-elements')) {
92
+ var data = $(this).data(ui.item.id.toString());
93
+ var update_elements = $.parseJSON($(this).attr("data-update-elements"));
94
+ for (var key in update_elements) {
95
+ $(update_elements[key]).val(data[key]);
96
+ }
97
+ }
98
+ }
99
+ $(this).trigger('railsAutocomplete.select');
100
+
86
101
  return false;
87
102
  }
88
103
  });
@@ -96,6 +96,7 @@ $(document).ready(function(){
96
96
  }
97
97
  }
98
98
  }
99
+ $(this).trigger('railsAutocomplete.select');
99
100
 
100
101
  return false;
101
102
  }
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '0.6.4'
2
+ VERSION = '0.6.5'
3
3
  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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 5
10
+ version: 0.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Padilla