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

552
Visualizações
Simulating a file input click with .click() does not work in iOS - Cordova

I am using React to build a web-app wrapped with Cordova to be a native app on android/iOS. I am having trouble with specifically iOS, specifically with simulating a click on a file input with .click()

I am using this library: https://github.com/odysseyscience/react-s3-uploader

Here is my code, very simple:

<button onClick={(e) => { e.preventDefault() $('#fileinput').click() }} className='btn btn--no-bg btn--w-icon uploader'>

The element with id fileinput is a rendered version of the react uploader, but in plain HTML looks like this:

<input type="file" id="fileinput" class="hidden react-s3" accept="image/*">

I have done a bunch of testing and the problem is occuring in the .click() jquery event. The first onClick is definitely being triggered, but nothing happens (in iOS) when $('#fileinput').click() is called.

This portion of code works in a web browser as well as in my android simulator, but once again not in my iOS simulator.

When I go into the console for all three environments (desktop, iOS, android), and run the code $('#fileinput').click() in the console, the input is clicked and the photo selection is triggered for android and desktop, but does nothing on iOS.

Ive done a bunch of research, a few solutions I found that dont work are: adding pointer: cursor to either the button or the input, changing the button to an a tag, changing display:none to visibility: hidden on the hidden input, and trying all different versions of .click() i could find (vanillaJS, .trigger, .touchstart, .touchend, .live, etc.)

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I had the same issue and this worked:

$('#fileinput').trigger("click"); 

and don't hide the file input but css it off screen like:

#fileinput {
    position:absolute;
    top:-9999px;
}

I don't think you can trigger clicks on a hidden element in iOS

over 4 years ago · Santiago Trujillo Relatório

0

I use:

document.getElementById("fileinput").discpatchEvent(new Event("click"))
over 4 years ago · Santiago Trujillo 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