Answer the question
In order to leave comments, you need to log in
Why doesn't event.preventDefault() work in React.js on onKeyUp event?
Hello.
Please tell me here is the code
<input type="text" placeholder={item.name} onKeyUp={self.checkName} />
checkName: function (event) {
event.preventDefault();
},
Answer the question
In order to leave comments, you need to log in
You answered your own question.
But in general:
keyup
Fires when the user releases a key, after the default action of that key has been performed.
But how then to make it so that if the user enters a value into the string that does not match the regular expression, the event.preventDefault() function is executed? because keyDown and keyPress are not suitable for this, since they take the old values
handleChangeSomeValue(e) {
const nextVal = e.currentTarget.value;
if (!isValid(nextVal)) {
return;
}
this.setState({ someValue: nextVal });
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question