2
Hello I have a problem here when I create an input dynamically and it should work the Widgets autocomplete jquery ui. I saw several forums and they show how to make it work, but 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" );
right after javascript appendchild. Didn’t work and caused error.
I tried too
$(document.body).on('focus', 'input.item_extra' ,function(){
// código
}
according to some tutorials this should also work, but with me not.
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 am doing so(I use javascript, but there is also another option in jquery 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 created input to this plugin?