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

278
Vistas
React client side validation with material-ui component

Some material-ui components have errorText as a prop which we can use to show errors, But, doing that in react become lot complex if my form has large number of field components.

Please suggest the best way to handle client-side validation with material-ui comonents.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I think your issue is that you have to manage a lot with state/store. In react validation is complex because of one-way binding.

This library https://github.com/vishalvisd/react-validator is one which I found that supports material-ui component validation. Though in general you may use this to validate any component.

over 4 years ago · Santiago Trujillo Denunciar

0

I would suggest using some HoC (Higher-order Component) approach. I tested many solutions for form validation in React JS, the one that I always choose is: react-validation-mixin. Take a look at this example.

Example of the standard input:

<input
  type='text'
  placeholder='Username'
  value={this.props.username}
  onChange={this.onChange('username')}
  onBlur={this.props.handleValidation('username')}
/>

In this example value of that input comes from props (example with Flux implementation) and that's probably what you aim for too (lots of inputs). onChange will need to handle value change so that this.props.username gets updated too and onBlur will trigger validation check (so that the error will show up once user leaves the input).

In order to get the error message, use: this.props.getValidationMessages('username')

It's a universal solution and you can use it in different libs. But taking TextField from material-ui, as you asked:

<TextField
  floatingLabelText="Username"
  value={this.props.username}
  errorText={this.props.getValidationMessages('username')}
  onChange={this.onChange('username')}
  onBlur={this.props.handleValidation('username')}
  ...
/>

Remember to use HoC with your component: export default validation(strategy)(UserLogin) That way, you will get all the necessary helper methods in props.

over 4 years ago · Santiago Trujillo Denunciar

0

If you are using Redux in React project, redux-form give you a simple way to implement form validation.

Check this out: http://redux-form.com/6.4.3/examples/syncValidation/

over 4 years ago · Santiago Trujillo 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