admin管理员组文章数量:1195301
I want to fire a function when the user hit backspace in a textbox. I have searched on stack overflow and React Native docs but there is not a relevant answer. basically, I don't know whats the keyname for backspace
<TextInput
onChangeText = {e => {
e === 'BackSpace' ? alert('delete') : alert(e)
}}/>
I want to fire a function when the user hit backspace in a textbox. I have searched on stack overflow and React Native docs but there is not a relevant answer. basically, I don't know whats the keyname for backspace
<TextInput
onChangeText = {e => {
e === 'BackSpace' ? alert('delete') : alert(e)
}}/>
Share
Improve this question
asked Oct 31, 2018 at 14:30
SyedSyed
5303 gold badges10 silver badges27 bronze badges
2 Answers
Reset to default 27onChangeText
only sends the updated text value. It does not send any other information such as keypress. onChange
sends much more information, onChangeText
is just for convenience.
You could use onKeyPress
<TextInput
onKeyPress={({ nativeEvent }) => {
nativeEvent.key === 'Backspace' ? //do action : //other action
}}
/>
You cannot use alert
however, you must use Alert
in react-native
which has a different API.
However it might be easier to just use onChangeText
depending on what you're trying to accomplish. If the text value sent is shorter than the currently controlled text value, you can handle whatever backspace code you're using and manage the text input value in one place.
As suggested here you could try something like this :
<TextInput
onKeyPress = {e => {
e.keyCode === 'Backspace' ? alert('delete') : alert(e)
}}/>
本文标签: javascripthow to check for backspace(delete) keyPress in react native (iOS)Stack Overflow
版权声明:本文标题:javascript - how to check for backspace(delete) keyPress in react native (iOS) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738428060a2086240.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论