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

108
Views
React Bootstrap Modal not working on submit Button

I am looking to send the value from the Form.Control to the button so I can do some logic but I cannot seem to get this value from the input. I tried using reft but I cant use refs in a functional component, so I'm using the textInput. Please help, been stuck for 3 days. thx

import React from "react";
import { Modal, Form, Row, Col, Button } from "react-bootstrap";
import "./Login.css";

export const ForgotPassword = (props) => {
  let textInput = null;

  const handleClick = () => {
    console.log("i am here", textInput.focus());
  };

  return (
    <>
      <Modal
        {...props}
        aria-labelledby="contained-modal-title-vcenter"
        centered
      >
        <Modal.Header closeButton>
          <Modal.Title id="contained-modal-title-vcenter">
            Forgot Password
          </Modal.Title>
        </Modal.Header>
        <Modal.Body className="show-grid">
          <Form.Label>Please enter your Employee ID.</Form.Label>
          <Row>
            <Col className="lm-qus" md={5}>
              Employee ID:
            </Col>
            <Col md={7}>
              <Form.Control
                type="text"
                required
                name="answer"
                placeholder=""
                ref={(input) => {
                  textInput = input;
                }}
              />
            </Col>
          </Row>
        </Modal.Body>
        <Modal.Footer>
          <Button onClick={props.onHide}>Cancel</Button>
          <Button onClick={handleClick} type="submit">
            Continue
          </Button>
        </Modal.Footer>
      </Modal>
    </>
  );
};

this is what I have, I enter an ID, the when I click continue, I don't have a value there

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

0

This is not a modal specific problem. Make your Form.Control a controlled input by providing "value" attribute. Define state and set this state on change event of the input. You can then access this state everywhere, including the button:

const [value, setValue] = React.useState("");
const handleChange = (event) => setValue(event.target.value);
const handleClick = () => alert(value);

https://codesandbox.io/s/objective-pond-rs8r9f

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!