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

209
Visualizações
How to abort submit of <button> tag without "type" attribute?

I understand that without "type" attributes are submitted inside "form" tag. (this question)

One of the third-party react components I use has a button that doesn't have a type attribute, which causes it to be submitted unconditionally.

Is there a way to stop submitting a form if there is such a button in a third party component?

This code is just an example:

import React from "react";
import {SamethingComponent} from "samething-package";

export const MyComponent = () => {
    
    const handleSubmit = (e) => {
        // doSomething.
    }
    return (
        <>
            <form onSubmit={handleSubmit}>
                {/* Component containing a button with no type attribute */}
                <SamethingComponent/>
                {/* This is needed as a normal submit button. */}
                <button type="submit">Submit!</button>
            </form>
        </>
    );
};
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The default type for a <button> is submit. Setting type='button' should prevent it from submitting when clicked and turn it into a regular button.

about 4 years ago · Juan Pablo Isaza Relatório

0

Use onSubmit of the parent form.

<form onsubmit='event.preventDefault()'>
  <button>Click me with impunity</button>
</form>

about 4 years ago · Juan Pablo Isaza Relatório

0

HTML:

<form id="form">
 <input type="text"/>
 <button>Submit</button>
</form>

JS:

const form = document.getElementById("form")

form.addEventListener('submit', event => {
  event.preventDefault()
})

You can prevent all form submission in the form element by calling preventDefault on event object.

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