O combobox destacado em vermelho ao ser selecionado, dispara uma ação no jquery para pegar valores dos outros inputs e adicionar no input em azul(tipo hidden, mas esta text para voces verem o que esta acontecendo) até aí tudo bem, problema que se for clicado novamente ao invés de atualizar o valor do input azul, ele esta acrescentando novamente os novos valores aos valores antigos. Já tentei user empty e nada, ja tentei limpar a o valor do input azul e acrescentar novamente os valores e nada
var scp_opts = {
width: 260,
matchContains: true,
selectFirst: false,
appentTo: '#input_configurations_plan',
source: function(request, response){
let plan = $(".form_union_plans:last").val();
let split = plan.split("|");
$.ajax({
url: getUrl + "filter/code_per_plan",
type: 'get',
dataType: 'html',
data:{'term' : request.term, 'table' : split[1] }
}).done(function( codePlan ){
if( codePlan.length > 0 ){
codePlan = codePlan.split( ',' );
response( $.each( codePlan, function( key, item ){
return({
label: item
});
}));
}
});
},
select: function( event, ui ) {
var plan = $(".form_union_plans:last").val();
var split = plan.split("|");
var ch = $(".insert-factor-multiplier:last").val();
var number = $(".insert-ch:last").val();
var values = '';
$.ajax({
url: getUrl + "filter/value_code_per_plan",
type: 'get',
dataType: 'json',
data:{'term' : ui.item.value, 'table': split[1]}
}).done(function( response ){
var code = $(".search-code-plan:last").val();
if( response.value != "" ){
$(event.target).closest('tr').find('td .insert-value-code').val( response.value.replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, "$1.") );
var money = response.value.replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, "$1.");
}
values = plan +'|'+ ch +'|'+ number +'|'+ code +'|'+ money;
if( ( count++ ) == 0 ){
$(event.target).closest('tr').find('td .form_union_plans').val( values );
}else{
$(event.target).closest('tr').find('td .form_union_plans').val("");
$(event.target).closest('tr').find('td .form_union_plans').val( values);
}
});
}
}
values
... Não seria esse o problema? Você não deve estar reiniciando seu values...plan
... Aquivar plan = $(".form_union_plans:last").val();
vc pega o valor do último e depois faz um split pra mandar pro AJAX, e no done oplan
continua o mesmo.