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

303
Visualizações
HTML/JS - Upload file: Display loader only after file explorer is closed

I have an input(type=file), div and icon element

<i id="hexfile-upload-btn" class="material-icons icon upload-icon">file_upload</i>
<input id='hexfile-fileid' type='file' hidden/>
<div id="hexfile-loader" class="loader"></div> 

where the icon element has an eventlistener attched to it. The js code is:

function setup() {
    document.getElementById('hexfile-upload-btn').addEventListener('click', function(){
        openDialog('hexfile-fileid')
    });
}
function openDialog(file-upload-id) {
    document.getElementById(file-upload-id).click();
    document.getElementById('hexfile-loader').style.display = "inline-block"
    document.getElementById(file-upload-id).addEventListener('change', function(){
        updateTextBox(...)
    });
}

As the code currently stands, my loader element is displayed as soon as the user clicks the icon element (e.g. as soon as the file explorer window is openend).

What I would like is that the loader element is only displayed as soon as the file explorer window is closed and the file gets actually uploaded. Once the file is actually uploaded, I hide the loader.

So I guess I need to somehow listen to the event of the user actually pressing the "Open" button of the file explorer? I sadly couldn't work out how that would work. Or are there some other ways?

Any input on how to solve this would be really appreciated! Thank you!

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

0

Move the code that shows the loader to inside the change handler, that way the loader is shown when you select a file

function setup() {
    document.getElementById('hexfile-upload-btn').addEventListener('click', function(){
        openDialog('hexfile-fileid')
    });
}
function openDialog(file-upload-id) {
    document.getElementById(file-upload-id).click();
    document.getElementById(file-upload-id).addEventListener('change', function(){
        document.getElementById('hexfile-loader').style.display = "inline-block"
        updateTextBox(...)
    });
}
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