是否有可能有一个只允许小写输入的用于 native react 的 TextInput?
截至目前,尝试了以下代码:
state = { login: '' }
changeUsernameToLowercase = (input) => {
var temp = input.toLowerCase()
this.setState({login: temp})
}
<TextInput
onChangeText={(login) => this.changeUsernameToLowercase(login)}
value={this.state.login}
autoCapitalize='none' />
但它似乎不适用于某些 android 设备。
也许有更有效的方法来做到这一点?
最佳答案
这可能会解决您的问题,它对我有用。
在 TextInput
内添加这三行, 原创 answer source
autoCapitalize="none"
secureTextEntry={true}
keyboardType={"visible-password"}
例子
import React, { useState } from "react";
import { View, TextInput } from "react-native";
export default function App () {
const [text,setText] = useState('');
return (
<View>
<TextInput
autoCapitalize="none"
secureTextEntry={true}
keyboardType={"visible-password"}
style={{height: 40, borderColor: 'gray', borderWidth: 1,width:"100%"}}
value={text}
onChangeText={ text => setText(text.toLowerCase()) }
/>
</View>
);
}
关于react-native - React Native 只允许 TextInput 的小写输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53038187/