Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!