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

181
Views
Address Can't be Empty inside Whole Field in Javascript

In the below screenshot, User have to Add Address but If they enter Space bar 4-5 time then this input type assume it a value & then addres submit button Proceed,

<div className={AddressBox} style={{ marginTop: "1rem" }}>
                
              </div>
<button className="submit_Button" type="button" onClick={() => submit()}><span>Submit</span></button>

But If I apply .trim() inside value option i.e.. value={form.address_1.trim()} then I don't have any option to give space between the address.

Guide me in this.

On Submit Button, I put this below condition

if (!address.length) {
    alert( 'Enter Your Address' );
    return;
  }

Requirement:- If I enter multiple space inside Input type="text" box then form is not submitted. enter image description here

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

0

You can use trim on onBlur to remove sapce when click outside the input:

onChange={(e) => handleChange(e)}
value={form.address}
onBlur={(e) => handleChange({ target: { value: e.target.value.trim() } })}
about 4 years ago · Juan Pablo Isaza Report

0

I would create a flag to specify if the form can be submitted.

Something like (simplified version)

const canSubmitForm = form.address.trim() !== '';

and then on the button set the disable attribute accordingly

<button 
  className="submit_Button" 
  type="button" 
  onClick={() => submit()}
  disabled={!canSubmitButton}
  >
  <span>Submit</span>
</button>

The test above is very simple, you should create a validation for the whole form

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!