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

267
Views
Nextjs react-bootstrap onSubmit doesn't work

Details

I want to make a form for a register page, after entering the form and hitting submit, the react-bootstrap button will call handleSubmit() using onSubmit={}.

Expected and actual result

I tried multiple ways to write onSubmit={}, you can see some of them in the Form tag. None of them worked. But the third one, console.log(), did get executed twice when submit button is clicked.

What I have tried

I don't where to start debugging this, so I tried way to write onSubmit and the function

  • Anonymous function in onSubmit={}

  • Anonymous async function in onSubmit={}

  • Anonymous function

  • Anonymous async function

  • top-level function

  • top-level async function

  • onSubmit={e=>console.log(e)}

None of these worked during testing.

Code

here is a simplified sample with the same problem.

import { Form, Button } from "react-bootstrap";

export default function Home() {

    const handleSubmit = (event) => {
        event.preventDefault()
        console.log("test");
    };

    return (
        <>
            <Form
                noValidate
                // onSubmit={e=>handleSubmit(e)}
                onSubmit={handleSubmit}
                // onSubmit={console.log("hello world")}
            >
                <Form.Group>
                    <Form.Label>Username</Form.Label>
                    <Form.Control
                        onChange={() => handleCheck}
                        type="text"
                        defaultValue={"test"}
                        required
                    />
                </Form.Group>
                <Button type="submit">
                    Submit
                </Button>
            </Form>
        </>
    );
}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

handleSubmit should get a preventDefault():

const handleSubmit = (e) => {
  e.preventDefault()
  console.log("test")
}

You're also bringing in useState but no where are you showing how you're using it. You could always update state from handleSubmit.

about 4 years ago · Juan Pablo Isaza Report

0

I think I have found the problem.

The reason I use console.log() to check whether the function is executed is because I want to print out some value. I expected it to print out in the terminal, but this is the front end, all console.log() goes to browser console, instead of terminal. So the code onSubmit={handleSubmit} did execute properly.

Play around with the official example : Nextjs Doc: Building forms

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!