Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda