Reputation: 2354
I'm using jQuery autocomplete feature (http://jqueryui.com/autocomplete) and Django dynamic-formset (http://code.google.com/p/django-dynamic-formset/). One of my formset fields needs to use autocomplete, so I attach it using (simplified):
$('input[name$=select]').autocomplete({source:'my_url/', minLength: 3});
I call this on document ready and it works fine (gets data from ajax). However, if I add new row with django-dynamic-formset and handle its 'added' event with:
function(row){
$(row).find('input[name$=select]').autocomplete({source:'my_url/', minLength: 3});
}
it doesn't work with newly added rows. What's wrong?
UPDATE: Tried to use classes instead - no result Tried to use on()/live() - no result Tried to destroy autocomplete after new row is added - no result (it destroys, but does no create).
Upvotes: 1
Views: 1252
Reputation: 4839
I just tested this code with jquery.formset-1.2 and it definitely works:
function enableAutocomplete(context) {
$('input[name$=select]', context || null).autocomplete({source:'my_url/', minLength: 3});
}
$(document).ready(function() {
$('.foo').formset({
added: function(row) {
enableAutocomplete(row);
}
});
enableAutocomplete();
});
Upvotes: 1