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

200
Visualizações
How to pause a <form> submisson, do some work, and then continue with the submission

I have to pass a form to a route, but before that I want to use a modal to request confirmation from the user. I am using preventDefault() to stop the submission and handle the confirmation, but now I need to continue with the normal form submission:

<script type="text/javascript">
  $(".btn-close").click((x) => {
    x.preventDefault();
    var text = $(this).val();
    $("#modal_body").html(text);

    $("#removeConfirm").click(() => {
      //$(this).submit();
      //I need to continue with the form submission here
      console.log("Confirmed!");
    });
  });

</script> 

"text" is a value I am passing to the modal;

"#removeConfirm" is the confirmation button in the modal;

I tried "$(this).submit()" but it's not working, any ideas?

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

0

preventDefault() isn't going to stop your form from submitting.

It's likely going to be easier to have the submit handler trigger from the modal itself, since you can't really have the data hang in limbo like you're proposing (unless you write the values to some higher order store of course).

about 4 years ago · Juan Pablo Isaza Relatório

0

$(this).submit() is not working because "this" is the button $(".btn-close") and not the form.

For the form, instead of using a submit button, use a button with a Javascript function and manage there the submission, something like:

<label>Name</label>
<input type="text" name="name" value="" />
<br/>
<label>Phone</label>
<input type="text" name="phone" value="" />
<br/>

<a id="processBtn" class="btn btn-default" href="javascript:;" >Process</a>
<script>
    $('#processBtn').click(function(e){
        e.preventDefault();
        if (doStuff()) {
            console.log("there we go!");
            $("#waitform").submit();
        }

    });
    function doStuff()
    {
        console.log("i'm sending the form in a sec");
        return true;
        //you can also add a condition and return false if you don't want to submit the form
    }
</script>
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