dockwa / simple-react-validator

A simple react form validator inspired by Laravel validation.
https://dockwa.github.io/simple-react-validator
MIT License
278 stars 78 forks source link

How to change Input box red color while input box empty #128

Open senthilmca90 opened 5 years ago

senthilmca90 commented 5 years ago

Hi, this is finding simple validation, but while hitting the submit button the input box is not showing red color

image

anyone can help me how to write condition red color bor.

damanmokha commented 4 years ago

Hi, any update on that? @senthilmca90 did you managed to find the solution

stuyam commented 4 years ago

My suggestion would be to define the validator above the input maybe in the top of the render() method for example and assign it to a variable. That way you can use the response to check if you should show a different border for the input and show the message below for example. If nothing is returned that means validation passed and will be null. Something like this:

render() {
  let emailValidator = this.validator.message('email', this.state.email, 'required|email')
  return (
    <div>
      <input className={emailValidator ? 'border-red' : 'border-default'} ....../>
      {emailValidator}
    </div>
  )
}
Hansi4348 commented 1 year ago

how we do this in react native ?