1
I’m creating a form and I’ve turned the values typed into objects to save into a cookie, but I’m not able to take from the second value of that object, I’d like to take all the values, follow the code, I’ve tried to put only the recruit code but still he’s underfined. If you could give me a hand
<div class="form-prospects">
<a class="add-prospects" href="#">Adicionar Prospects</a>
</div>
function Action_InternalFunctions() {
var formProspectsObject = $(containerClass+' .form-prospects');
if (formProspectsObject.length) {
Setup_FormProspects(formProspectsObject);
}
}
var formValuesProspect = {
prospect: [
{consultor:'',
recruta:'',
venda:''}
]
};
function Setup_FormProspects(formProspectsObject) {
$.each(formValuesProspect, function(index, value) {
console.log(index+' '+value);
});
formProspectsObject.each(function(i, val) {
var thisProspectObject = $(this);
var thisGoto = $(this).find('.goto');
thisGoto.css('display','none');
//Gera =====
//var countProspect = 0;
var countProspect2= 0;
$.each(formValuesProspect['prospect'], function(index, value) {
console.log(index+' '+value);
thisProspectObject.prepend('<p class="consult consult-'+index+'">Consultor: <input type="text" placeholder="Consultor" name="consultor" data-consult="'+index+'" id="consultor'+index+'" class="consultor consultor-'+index+'"></p>'+
'<p class="recruit recruit-'+index+'">Número de recrutas: <input type="text" placeholder="Quantidade de recrutas" name="recruta" data-recruit="'+index+'" id="recruta'+index+'" class="recruta recruta-'+index+'"></p>'+
'<p class="buy buy-'+index+'">Volume de Vendas: <input type="text" placeholder="Volume de Vendas" name="venda" data-buy="'+index+'" id="venda'+index+'" class="venda venda-'+index+'"></p>');
setTimeout(function(){
//$('.consultor-'+index).val(value['consultor']);
$('.recruta-'+index).val(value['recruta']);
$('.venda-'+index).val(value['venda']);
}, 0.1);
//watchProspects($('.consultor-'+index));
watchProspects2($('.recruit-'+index));
//countProspect = index;
countProspect2 = index;
if(formValuesProspect['prospect'].length-1==index){
thisProspectObject.find('.add-prospects').click(function(e){
e.preventDefault();
//var ddl = thisProspectObject.find('.consult-'+countProspect);
var ddl2 = thisProspectObject.find('.recruit-'+countProspect);
//var oldcountProspect = countProspect;
var oldcountProspect2 = countProspect2;
//countProspect = countProspect+1;
countProspect2 = countProspect2+1;
console.log(countProspect2);
//ddl.before('<p class="consult consult-'+countProspect+'"></p>');
ddl.before('<p class="recruit recruit-'+countProspect+'"></p>');
//ddlHTML = ddl.html().split(oldcountProspect).join(countProspect);
ddlHTML2 = ddl2.html().split(oldcountProspect2).join(countProspect2);
//$('.consult-'+countProspect).html(ddlHTML);
$('.recruit-'+countProspect2).html(ddlHTML2);
//watchProspects($('.consultor-'+countProspect));
watchProspects2($('.recruit-'+countProspect));
});
}
});
});
}
// function watchProspects(element){
// var thisInput = element;
// thisInput.val(formValuesProspect[thisInput.attr('name')]);
// thisInput.keyup(function() {
// if(formValuesProspect['prospect'][Number(thisInput.data('consult'))]!={}){
// formValuesProspect['prospect'][Number(thisInput.data('consult'))] = {};
// console.log(thisInput.data('consult'));
// }
// formValuesProspect['prospect'][Number(thisInput.data('consult'))][thisInput.attr('name')] = thisInput.val();
// });
// }
function watchProspects2(element){
var thisInput = element;
thisInput.val(formValuesProspect[thisInput.attr('name')]);
thisInput.keyup(function() {
if(formValuesProspect['prospect'][Number(thisInput.data('recruit'))]!={}){
formValuesProspect['prospect'][Number(thisInput.data('recruit'))] = {};
console.log(thisInput.data('recruit'));
}
formValuesProspect['prospect'][Number(thisInput.data('recruit'))][thisInput.attr('name')] = thisInput.val();
});
}