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

247
Visualizações
submiting form on eventListener('click') - SweetAlert2

so I'm using the SweetAlert2 to validate form entries(if its empty). However my problem is here:

JS:

t = document.getElementById("kt_modal_new_target_submit");     
    e.preventDefault(), t.addEventListener("click", (function(e) {            
                      n && n.validate().then((function(g) {
                        console.log("validated!"), "Valid" == g ? (t.setAttribute("data-kt-indicator", "on"), t.disabled = !0, setTimeout((function() {
                            t.removeAttribute("data-kt-indicator"), t.disabled = !1, Swal.fire({                    
                                text: "User added successfuly",
                                icon: "success",
                                buttonsStyling: !1,
                                confirmButtonText: "Close",
                                customClass: {
                                    confirmButton: "btn btn-primary"
                                }                            
                            }).then((function(t) { 
                                 t.isConfirmed && o.hide()
                            }))
                        }), 1000)) : Swal.fire({
                            text: "Sorry, looks like there are some errors detected, please try again.",
                            icon: "error",
                            buttonsStyling: !1,
                            confirmButtonText: "Ok, got it!",
                            customClass: {
                                confirmButton: "btn btn-primary"
                            }
                        })
                    }))
               }))

HTML:

<form id="kt_modal_new_target_form" class="formek" method="post"></form>
        <button type="submit" name="addUser" id="kt_modal_new_target_submit" class="btn btn-primary"<span class="indicator-label">Add</span>
        <span class="indicator-progress">Adding...
        <span class="spinner-border spinner-border-sm align-middle ms-2">
    </span>
    </span>
    </button>

If I don't use e.PreventDefault() then my form will get submited. If I change "click" to "submit" my form will get submited.

I tried jQuery, document by id and submiting nothing works. My goal is to add user before the "User added succesfully" message pops up.

So far

about 4 years ago · Juan Pablo Isaza
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