We are working on autocomplete with dynamically inserted elements with jquery (did autocomplete on static elements before). Here is the html source code for one autocomplete add
you can put the onload code in a function, so when you create new content, you fire the function onload again...
$(document).ready(function() {
function returnAccess(){
//all your code when the page load
//all the code you need to run like events or something else...
}
function createContent(){
//code that create content
//then you run returnAccess() again
returnAccess();
}
returnAccess();
});
so when you create new content, you fire returnAccess() again... even you can put your function createContent inside return access if the new content execute too the create content...
setTimeout solves the problem:
setTimeout(function(){
$("[id^='requisition_material_items_attributes_'][id$='_item_name_autocomplete']").each(function (){
$(this).autocomplete({
minLength: 1,
source: $(this).data('autocomplete-source'),
select: function(event, ui) {
$(this).val(ui.item.value);
}
});
});
}, 5000);