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

221
Vistas
Svelte - event modifier "once" on form submit not working

Any idea why the once modifier doesn't work on form submitting in Svelte?

In the following example:

<form action="./" on:submit|preventDefault|once={() => alert('You submitted the form')}>
  <button type="submit">Save</button>
</form>

when I submit the form first time - I see the alert, but after that, when I submit - the page refreshes - as a normal form submitting.

(I tried with the button on:click - on:click|preventDefault|once... - but got same result.)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Looks like the 'once' is working, but after running and being removed the default submit behaviour of the form seems to be active again.

Couldn't find any information if disabling this listener is possible any other way than by adding a submit listener with preventDefault.

But this way, when adding a second listener only preventing the default, you can see that 'once' is only executed once -> REPL

<script>    
    
    function submitOnce() {
        console.log('this logs once')
        // put logic here you want to execute once
    }
    function handleSubmit() {
        // console.log('this logs with every submit')
        // this prevents default submit behaviour
    }
        
</script>

<form on:submit|preventDefault={handleSubmit} on:submit|once={submitOnce}>
  <button>Submit</button>
</form>

can simply be replaced by on:submit|preventDefault={() => {}}

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