Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
Disabling input is delayed

I have an Export button on my page that is creating a PDF (this part is working). During the export process I would like to disable some input or show an overlay to block the user to modify the page. I'm using the code below:

function RenderSelectedChartJsToPDF() {
  // Option 1
  $('.featureInput').attr("disabled", true);
  $("#fileName").attr("disabled", true);
  $("#pdfExport").attr("disabled", true);
  // Option 2
  $("#overlay").show();

  window.jsPDF = window.jspdf.jsPDF;
  const pdf = new jsPDF('portrait', 'mm', 'a4', true);    //portrait or landscape

  var currentTopPosition = topMargin; // Initialisation of the working position.

  RenderPDFHeader(pdf, currentTopPosition);
  RenderPDFGeneralData(pdf, currentTopPosition);
  RenderPDFFooter(pdf, footerHight, 1, pdf.internal.pageCount);

  pdf.save($("#fileName").val() + '.pdf');

  // Re-enable input here
}

The issue is that when I click the export button the PDF will be render and at the end (when the download starts) then the inputs will be disabled. I would like the input to be disabled first then start to build the PDF.

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As mentioned by @PeterKrebs the issue seems to be the PDF library blocking the browser. I used a setTimeout function to solve my issue as follow:

function RenderSelectedChartJsToPDF() {
  $('.featureInput').attr("disabled", true);
  $("#fileName").attr("disabled", true);
  $("#pdfExport").attr("disabled", true);

  setTimeout(() => { RenderPDF(); }, 1000);    
}

function RenderPDF() {
  window.jsPDF = window.jspdf.jsPDF;
  const pdf = new jsPDF('portrait', 'mm', 'a4', true);    //portrait or landscape

  var currentTopPosition = topMargin; // Initialisation of the working position.
  RenderPDFHeader(pdf, currentTopPosition);
  RenderPDFGeneralData(pdf, currentTopPosition);
  RenderPDFFooter(pdf, footerHight, 1, pdf.internal.pageCount);
  pdf.save($("#fileName").val() + '.pdf');

  // Re-enable input here
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda