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

163
Views
How to prevent triggered all forms inside a map at the same time using react hook form?

How to handle multiple forms in .map in reactjs using react-hook-form? the problem is when I click the button all forms get triggered and show errors like in this image Image Error , and the thing is I want every form be separate from each other and activate just when I click a button and obtain the data corresponding


{Order.orderDetails.map((item, index) => (
  <form onSubmit={handleSubmit2(ChangeProductStatus)}>
     <div className="form-control mb-5">
        <label className="text-medium font-semibold">Change Status Order</label>
          <select {...register2('productStatus', {required: ' Campo Requerido'})} className={(errors2.productStatus && ' select-error ') + ' select select-bordered  '}>
             <option value="Pendiente">Pending</option>
              <option value="Enviado">Sended</option>
         </select>
     </div>
     <button type="submit" onClick={() => validate(item.idOrderDetail)} className="btn btn-block  mb-5 normal-case">
              Save
      </button>
</form>
))}

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

0

I think the map is correct my guess is that when you use onSubmit={handleSubmit2(ChangeProductStatus)} you are executing the function so I think you need to change to a function similar to the one for onClick. Something like:

<form onSubmit={() => handleSubmit2(ChangeProductStatus)}>

Just in case that you don't want to refresh the page after submit you can change the button type to 'button' instead of 'submit'

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!