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

278
Views
how to create a form which will only allow to submit if the input is not empty and is > 0?

I want to make a logic before submitting which states that input value shouldn't be any empty value and it should be greater than 0.

 const minValue = (input) => {
      if(input < 0){
       alert('input has to be greater than 0')
      }else{
        return input;
      }
    }    


 <Form className  = "workout-form">
    <div className ="form-row">
              <label className ="form__label">Distance</label>
              <input type = 'number' value = {distance}  min = '0' onChange = {(e) => setDistance(minValue(e.target.value))} className ="form__input form__input--distance" placeholder="mi"  autoFocus required/>
            </div>
     <button className ="form-btn" onClick = {submitWorkout}>Add Workout</button>
    </Form>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If this code works for checking for negative values you should be able to change if (input < 0) to if ((input < 0) || (input != ""))

about 4 years ago · Juan Pablo Isaza Report

0

const handleChange = e => {
    const value = parseInt(e.target.value);
  if(!isNaN(value) && value > 1){
    setDistance(value)
  }
}
onChange={handleChange}

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!