0
I have an order registration page, where if the user selects the "no" option in the checkbox, it means that the order is for delivery if he selects "yes", he comes to remove the product in the store. However a bug happens if the user fills in all the delivery data first and only then selects the "no" option, the javascript function deletes the data that was typed/selected in the form fields. Follow code in Java.
$(document).on("change", "input[type=radio]", function() {
rdRetirar = $('[name="rdRetirar"]:checked').val();
rdIdem = $('[name="rdDestinaIdemReme"]:checked').val();
if (rdIdem == "sim") {
var selremetente = $('#selremetente').val();
$('#seldestinatario').val(selremetente);
$('#seldestinatario').prop("required", false);
var txtemail = $('#txtemail').val();
$('#txtemaild').val(txtemail);
var telefone1 = $('#telefone1').val();
$('#telefone1d').val(telefone1);
var telefone2 = $('#telefone2').val();
$('#telefone2d').val(telefone2);
var selEstado = $('#selEstado').val();
$('#selEstadod').val(selEstado);
$('#selEstadod').prop("required", false);
var selCidade = $('#selCidade').val();
$('#selCidaded').val(selCidade);
$('#selCidaded').prop("required", false);
var selBairro = $('#selBairro').val();
$('#selBairrod').val(selBairro);
$('#selBairrod').prop("required", false);
var logradouro = $('#txtlogradouro').val();
$('#logradourod').val(logradouro);
var numero = $('#txtnumero').val();
$('#numerod').val(numero);
var complemento = $('#complemento').val();
$('#complementod').val(complemento);
if (selEstado == "") {
alert("Favor preencher o campo Estado na seção do Remetente!");
$("#rdDestinaIdemRemeN").prop("checked", true);
$("#DivdoDestinatario").show("slow");
} else if (selCidade == "") {
alert("Favor preencher o campo Cidade na seção do Remetente!");
$("#rdDestinaIdemRemeN").prop("checked", true);
$("#DivdoDestinatario").show("slow");
} else if (selBairro == "") {
alert("Favor preencher o campo Bairro na seção do Remetente!");
$("#rdDestinaIdemRemeN").prop("checked", true);
$("#DivdoDestinatario").show("slow");
} else if ((logradouro == "") && (complemento == "")) {
alert("Favor preencher o campo Logradouro ou Complemento na seção do Remetente!");
$("#rdDestinaIdemRemeN").prop("checked", true);
$("#DivdoDestinatario").show("slow");
} else if ((numero == "") && (complemento == "")) {
alert("Favor preencher o campo Número ou Complemento na seção do Remetente!");
$("#rdDestinaIdemRemeN").prop("checked", true);
$("#DivdoDestinatario").show("slow");
} else {
$("#DivdoDestinatario").hide("slow");
$("#DivdoDestinatarioCopiado").show("slow");
}
} else {
$("#DivdoDestinatario").show("slow");
$("#DivdoDestinatarioCopiado").hide();
$('#seldestinatario').val("");
$('#txtemaild').val("");
$('#telefone1d').val("");
$('#telefone2d').val("");
$('#selEstadod').val("");
$('#selCidaded').val("");
$('#selBairrod').val("");
$('#logradourod').val("");
$('#numerod').val("");
$('#complementod').val("");
$('#seldestinatario').prop("required", true);
$('#selEstadod').prop("required", true);
$('#selCidaded').prop("required", true);
$('#selBairrod').prop("required", true);
}
if (rdRetirar == 'sim') {
$('#rdDestinaIdemRemeS').prop("disabled", true);
$('#rdDestinaIdemRemeN').prop("disabled", true);
$('#seldestinatario').prop("disabled", true);
$('#txtemaild').prop("disabled", true);
$('#telefone1d').prop("disabled", true);
$('#telefone2d').prop("disabled", true);
$('#selEstadod').prop("disabled", true);
$('#selCidaded').prop("disabled", true);
$('#selBairrod').prop("disabled", true);
$('#logradourod').prop("disabled", true);
$('#numerod').prop("disabled", true);
$('#complementod').prop("disabled", true);
//Desabilita os campos de relacionados a terceirizada
$('#selTerceirizada').prop("disabled", true);
$('#selVeiculo').prop("disabled", true);
$('#txtvalortaxa').prop("disabled", true);
$('#txtvalortaxa').val("0,00");
} else {
//Reabilita os campos do destinatario
$('#rdDestinaIdemRemeS').prop("disabled", false);
$('#rdDestinaIdemRemeN').prop("disabled", false);
$('#seldestinatario').prop("disabled", false);
$('#txtemaild').prop("disabled", false);
$('#telefone1d').prop("disabled", false);
$('#telefone1d').prop("required", true);
$('#telefone2d').prop("disabled", false);
$('#selEstadod').prop("disabled", false);
$('#selCidaded').prop("disabled", false);
$('#selBairrod').prop("disabled", false);
$('#logradourod').prop("disabled", false);
$('#numerod').prop("disabled", false);
$('#complementod').prop("disabled", false);
//Reabilita os campos de relacionados a terceirizada
$('#selTerceirizada').prop("disabled", false);
$('#selVeiculo').prop("disabled", false);
$('#txtvalortaxa').prop("disabled", false);
}
});
What is
rdIdem
? Why values are changed to null whenrdIdem != "sim"
?– Woss
You are explicitly having the typed content deleted, I believe you need to review your logic...
– andrepaulo
if (rdIdem == "sim") {...}else{ nesse trecho voce apaga o valor de todos os campos}
I believe that if you remove this Else solves your problem.– Neuber Oliveira
@Neuberoliveira . Sorry, but it is not in the condition of rdIdem, this is doing the function certainly, the problem occurs in rdRetirar.
– Gabriel Filippi
@Andersoncarloswoss rdIdem is when the guy who is buying(sender) did not buy to give gift to another person so the recipient is equal(rdIdem) to the sender.
– Gabriel Filippi
If he marks it as a gift, then fills in everything and only then selects "no" on the takedown, the E-l where you delete everything will be executed, do you agree? You have to treat the two events separately, not together in the same eventListener.
– luislhl
@luislhl true, I did not realize that this bug happened, because as it was inside if’s I thought it would not occur. VLW. I will post how I resolved.
– Gabriel Filippi