Skip to content

Commit 01f6aae

Browse files
author
David Padilla
committed
Using .live to add autocomplete to fields created with AJAX
1 parent d16373d commit 01f6aae

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/cucumber/autocomplete.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Given /^I choose "([^"]*)" in the autocomplete list$/ do |text|
2+
page.execute_script %Q{ $('input[data-autocomplete]').trigger("focus") }
23
page.execute_script %Q{ $('input[data-autocomplete]').trigger("keydown") }
34
sleep 1
45
page.execute_script %Q{ $('.ui-menu-item a:contains("#{text}")').trigger("mouseenter").trigger("click"); }

lib/generators/templates/autocomplete-rails.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
* with the autocomplete URL as the value
66
*
77
* Example:
8-
* <input type="text" autocomplete="/url/to/autocomplete">
8+
* <input type="text" data-autocomplete="/url/to/autocomplete">
99
*
1010
* Optionally, you can use a jQuery selector to specify a field that can
1111
* be updated with the element id whenever you find a matching value
1212
*
1313
* Example:
14-
* <input type="text" autocomplete="/url/to/autocomplete" id_element="#id_field">
14+
* <input type="text" data-autocomplete="/url/to/autocomplete" id_element="#id_field">
1515
*/
1616

1717
$(document).ready(function(){
18-
$('input[data-autocomplete]').each(function(i){
18+
$('input[data-autocomplete]').live('focus', function(i){
1919
$(this).autocomplete({
2020
source: $(this).attr('data-autocomplete'),
2121
select: function(event, ui) {
@@ -27,4 +27,4 @@ $(document).ready(function(){
2727
}
2828
});
2929
});
30-
});
30+
});

0 commit comments

Comments
 (0)