console.log("JavaScript carregado com sucesso!");
function validarNome() {
const nomeInput = document.getElementById("nome");
if (!nomeInput) return false;
const valor = nomeInput.value.trim();
if (/^(?!(?:^$|^\d+$|^\d+(?:,\d+)+$)).+$/.test(valor)) {
alert("O campo do EMITENTE_NUM_CNPJ deve conter apenas números.");
return false;
}
return true;
}
function validarDestino() {
const destinoInput = document.getElementById("destino");
if (!destinoInput) return false;
const valor = destinoInput.value.trim();
if (/^(?!(?:^$|^\d+$|^\d+(?:,\d+)+$)).+$/.test(valor)) {
alert("O campo do DESTINATARIO_NUM_CNPJ deve conter apenas números.");
return false;
}
return true;
}
$(document).ready(function () {
$("#data_inicial, #data_final").inputmask("99/99/9999", { placeholder: "DD/MM/YYYY" });
});
function showLoader() {
const loader = document.getElementById("loader");
if (loader) {
loader.style.display = "block";
console.log("
} else {
console.warn("
}
}
function hideLoader() {
const loader = document.getElementById("loader");
if (loader) {
loader.style.display = "none";
console.log("
}
}
function performSearch(event) {
event.preventDefault(); // Impede o envio tradicional do formulário
nomeInput = document.getElementById("nome").value.trim();
destinoInput = document.getElementById("destino").value.trim();
console.log("Nome:", nomeInput, "Destino:", destinoInput); // Antes da verificação
if (nomeInput === "" && destinoInput === "") {
alert("Preencha pelo menos o campo de CNPJ do emitente ou do destinatário.");
console.log("
return false; // response.text())
.then(html => {
document.body.innerHTML = html;
let totalRecordsElement = document.getElementById("totalRecords");
if (totalRecordsElement && totalRecordsElement.value === "0") {
alert("Nenhum registro encontrado!");
}
})
.catch(error => {
console.error("Erro ao buscar dados:", error);
alert("Erro ao realizar a pesquisa!");
})
.finally(() => {
hideLoader(); // Oculta o loader após carregar os resultados
});
}
const form = document.getElementById("formPesquisa"); // Pegando pelo ID do formulário
if (form) {
form.addEventListener("submit", performSearch);
}
window.addEventListener("load", function () {
hideLoader();
});
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... on-are-met
Мобильная версия