Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:xaop/rails3-jquery-autocomplete

  • Loading branch information...
commit a9c39b32b3c23ea02455ac0bde851ddb2eb9e834 2 parents 45b2c36 + b0fd777
julien authored
Showing with 10 additions and 0 deletions.
  1. +6 −0 README.markdown
  2. +4 −0 lib/generators/templates/autocomplete-rails.js
View
6 README.markdown
@@ -326,6 +326,12 @@ As an example, here we directly put the sources array in our view but it is bett
Also note that you can pass a :for_search element in your source hash. This will be the text use for the autocompletion query.
+### Javascript on_select
+
+If you want to persom some custom javascript when a user select an element in the autocomplete item list, you can add it via the :on_select option:
+
+ f.autocomplete_field :brand_name, autocomplete_brand_name_products_path, :on_select => "alert('Hello World')"
+
## Formtastic
If you are using [Formtastic](http://github.com/justinfrench/formtastic), you automatically get the *autocompleted_input* helper on *semantic_form_for*:
View
4 lib/generators/templates/autocomplete-rails.js
@@ -131,6 +131,10 @@ $(document).ready(function(){
$($(this).attr('id_element')).val(ui.item.id);
}
};
+ var javascript_on_select = $(e).attr('on_select');
+ if (javascript_on_select) {
+ eval('(' + javascript_on_select + ')');
+ };
if ($(e).attr('submit_on_select') == 'true') {
$(e).closest("form")[0].submit();
};
Please sign in to comment.
Something went wrong with that request. Please try again.