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

229
Views
In React how would I disable onSubmit call for some text fields and not others?

I have a component dataModal that has two text boxes, a searchable data table, and a submit button. The Name and Date text boxes need to be filled out manually, and the dataTable is a component that can be searched via it's own text boxes to narrow down what data needs to be entered.

The problem that I am facing is when searching the data table using the text input fields pressing enter causes the form to submit. This is likely happening because the data table is in the form that the submit button is in.

Is there a way to have the text fields in the dataTable not submit the form while retaining the ability to submit the form when pressing enter in the name or date form?

const dataModal = (props) => {

  const { data, save, close } = props;
  const [name, setName] = useState();
  const [date, setDate] = useState();

  const handleSubmit = (e) => {
    if (e) e.preventDefault();
    save(name, date); // DB Call from parent
    close(); // Closes the modal
  }

  return (
  <form onSubmit={handleSubmit}>
    <customInput 
      name="NameTextField"
      captureInput={(value) => {setName(value)}}
    /> // Custom text box component

    <customInput
      name="DateTextField"
      captureInput={(value) => {setDate(value)}}
    />  // Custom text box component

    <searchableDataTable
      name="SearchableDataTable"
      data=data
    /> // Data Table with customInputs build the same as above that are used for filtering the data table

    <Button type="submit" /> // Submission button
  </form> 
  )
}

Moving the data table below the form tabs works, but it causes "ugly" rendering in which the submit button is in the middle of the modal, and not at the bottom. This is the fallback solution if I'm unable to figure this out.

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

0

let's assume you pick "Name" to be required (also assuming everything works in your custominput), you could try this:

const [buttonState, setButtonState] = useState();

const isValid = (value) => {
    // return true or false
}
...
<customInput 
    name="NameTextField"
    captureInput={(value) => {
        setName(value)
        setButtonState(isValid(value))
    }}
/>
...
<Button {buttonState ? disabled="disabled" : ""} />

Please note isherwood's comment also.

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!