Dheeraj Kumar
Dheeraj Kumar

Reputation: 120

Facing issue on onChange function in React

facing issue during getting target value in this case i can't be able to add the value. Whereas with same code some other places it is working fine. Please explain about expected scanarios. here is my code

<input type="text" value={filterEventValue} name='filterEventValue' autocomplete="off" onChange={ this.filterEventUsers} />


 filterEventUsers = (e) => {
        console.log("e ::", e.target);
    }

When I am typing inside text field key is is not being typed inside field. outPut: enter image description here

Upvotes: 0

Views: 160

Answers (1)

fullstack
fullstack

Reputation: 834

you should keep the input value in the state, and update it when typing:

constructor(props) {
  super(props);
  this.state = { filterEventValue: '' };
}

filterEventUsers = (e) => {
  console.log("e ::", e.target);
  this.setState({ filterEventValue: e.target.value });
}

render() {
   return (
    <input type="text" value={filterEventValue} name='filterEventValue'  
      autocomplete="off" onChange={this.filterEventUsers.bind(this)} />
   )
}

Upvotes: 1

Related Questions