I'm developing a budget form and I add and remove rows to register products in each row and have two autocomplete fields, where you search for the product by code or by name. The first line is always fixed to start the fill and in it the autocomplete works, and the others that are added as many times as the user wants is not working autocomplete. They do not 'catch the autocomplete event', it does not seem to 'see the DOM'.
Addition and removal of rows
(function($) {
RemoveTableRow = function(handler) {
var tr = $(handler).closest('tr');
tr.fadeOut(400, function(){
tr.remove();
});
return false;
};
AddTableRow = function() {
var newRow = $("<tr>");
var cols = "";
cols += '<td width="13%"> <div class="form-group"> <div class="input-group"> <div class="input-group-addon"><i class="ti-search"></i></div><input type="text" class="form-control input-sm" name="form_code_product[]" id="form_code_product" placeholder="0002"> </div></div></td>';
cols += '<td width="30%"> <div class="form-group"> <div class="input-group"> <div class="input-group-addon"><i class="ti-search"></i></div><input type="text" class="form-control input-sm" name="form_name_product[]" id="form_name_product" placeholder="Mesa"> </div></div> </td>';
cols += '<td><input type="text" class="form-control input-sm" name="form_price_product" id="form_price_product"> </td>';
cols += '<td><input type="text" class="form-control input-sm" name="form_quantity_product" id="form_quantity_product"> </td>';
cols += '<td><input type="text" class="form-control input-sm" name="form_total_product" id="form_total_product"> </td>';
cols += '<td><input type="text" class="form-control input-sm" name="form_obs_product"> </td>';
cols += '<td class="actions">';
cols += '<button class="btn btn-large btn-danger" onclick="RemoveTableRow(this)" type="button"> <i class="fa fa-close"></i></button>';
cols += '</td>';
newRow.append(cols);
$("#products-table").append(newRow);
return false;
};
})(jQuery);
Autocomplete
$(document).ready(function() {
$("#form_code_product, #form_name_product").autocomplete({
width: 260,
matchContains: true,
selectFirst: false,
appentTo: '#form_register_budget',
source: function(request, response){
$.ajax({
url: "filter/product_code",
type: 'get',
dataType: 'html',
data:{'term' : request.term }
}).done(function( products ){
if( products.length > 0 ){
products = products.split( ',' );
response( $.each( products, function( key, item ){
return({
label: item
});
}));
}
});
}
});
});