Hello I'm having a problem here when I create an input dynamically and it should work in jquery widgets autocomplete ui. I have seen several forums and they show how to make it work, however my problem is that the function that creates the input is in a javascript function. One of the ideas was to instantiate the plugin again, using
$( ".selector" ).autocomplete( "destroy" );
and then
$( ".selector" ).autocomplete( "instance" );
shortly after the appendChild of javascript. It did not work and it caused an error.
I've tried it too
$(document.body).on('focus', 'input.item_extra' ,function(){
// código
}
According to some tutorials, this should work, but not with me.
The code I use in the inputs already created is:
$.ajax({
url: "../_lib/siclop_auto_complete/itens_extras.xml",
dataType: "xml",
success: function( xmlResponse ) {
var dataItemExtra = $( "item_extra", xmlResponse ).map(function() {
return {
value: $( "item", this ).text()
};
}).get();
$( ".item_extra" ).autocomplete({ // Produto principal
source: dataItemExtra,
minLength: 0,
select: function( event, ui ) {
inclui_item_extra(ui.item.value,this.id);
this.value = "";
this.focus();
return false;
}
});
}
});
And to add the element, I'm doing so (I use javascript, but there's also another jquery option I found on the internet.):
var add_item_extra = document.createElement("input");
add_item_extra.setAttribute('type', 'text');
add_item_extra.setAttribute('placeholder', 'Adicionar Item Extra');
add_item_extra.setAttribute('class', 'input_item_extra');
//add_item_extra.className = 'item_extra';
$insert = jQuery(cell3);
$insert.append(add_item_extra);
$insert.find('.item_extra').autocomplete();
//cell3.appendChild(add_item_extra);
This attempt with jquery tbm did not work. How do I then add this javascript input to this plugin?