Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda