Sanjana
Sanjana

Reputation: 296

How to change the value of the input field using React?

I'm new to React. I'm going through this link "https://www.telerik.com/blogs/up-and-running-with-react-form-validation". My objective is how to change the error while entering the data

Upvotes: 0

Views: 164

Answers (1)

zimmerbimmer
zimmerbimmer

Reputation: 948

If you are receiving the error message literally from your API, I am assuming you are saving it somewhere in your state. All you have to do is remove that error message from your state as soon as your user starts typing in the field. Edit your input field like this:

<input onChange={() => this.setState({ ...this.state, errorMessage: '' })} />

By this way, as your user starts typing, the error message resets to an empty string (please replace errorMessage with the name you hold your error message in.)

Upvotes: 1

Related Questions