Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
¿Cómo validar los archivos que envían los usuarios antes de subirlos a un servidor? - JavaScript

Tuvo una mínima suerte.

En el siguiente fragmento de código, primero traté de evitar la propagación de eventos para que no se cargara todavía.

Tenía las siguientes suposiciones.

  1. La acción predeterminada del navegador ocurrirá antes de que mi detector de eventos sea golpeado.
  2. Puedo despachar el evento de nuevo después.
 <html> <input id="file-input" type="file"> </html> ... <script> let ignoreEventForSecondTime = false document.getElementById("file-input").addEventListener("click", (event) => { if (!ignoreEventForSecondTime) { event.stopImmediatePropagation() // Don't actually upload yet const input = event.target validate(input.files) // I only want this to run after users have picked the files ignoreEventTheSecondTime = true // Don't run this block after I refire the event input.dispatchEvent(event) // The intention is to let whatever event listener handle uploading the files afterwards. } else { ignoreEventTheSecondTime = false } }, { capturing: true }) </script>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto parece haber funcionado. El problema era que no podía simplemente enviar el mismo evento desde el que detuve la propagación, además de cambiar del controlador 'clic' al controlador 'cambiar' para poder ver los archivos después de que se haya completado el cuadro de diálogo del archivo.

 <html> <input id="file-input" type="file"> </html> ... <script> let ignoreEventForSecondTime = false document.getElementById("file-input").addEventListener("change", (event) => { // LINE CHANGED if (!ignoreEventForSecondTime) { event.stopImmediatePropagation() // Don't actually upload yet const input = event.target validate(input.files) ignoreEventTheSecondTime = true // Don't run this block after I refire the event input.dispatchEvent(new Event('change', event)) // LINE CHANGED } else { ignoreEventTheSecondTime = false } }, { capturing: true }) </script>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!