[英]how do I enable/disable textinput programmatically in expo?
the problem is that I am trying enable/disable fields in a form with the use of a 问题是我正在尝试使用形式启用/禁用表单中的字段
I have tried following the steps in this tutorial 我已经尝试按照本教程中的步骤进行操作
https://dev.to/skptricks/react-native-enable-and-disable-textinput-programmatically-1b99 https://dev.to/skptricks/react-native-enable-and-disable-textinput-programmatically-1b99
Here is where I have got to so far 到目前为止,这是我必须到达的地方
onPressButton = () => {
this.setState({ TextInputDisableStatus: false })
}
<TextInput
label="Name"
placeholder="Colin Molony"
autoCapitalize="none"
keyboardType="default"
keyboardAppearance="default"
returnKeyType="next"
returnKeyLabel="Next"
blurOnSubmit={false}
selectTextOnFocus={true}
style={styles.textInput}
editable={this.state.TextInputDisableHolder}
/>
ProfileScreen.navigationOptions = {
title: 'Profile Page',
headerRight: (
<Ionicons
style={{padding: 15}}
name={Platform.OS === 'ios' ? 'ios-create' : 'md-create'}
size={26}
onPress={this.onPressButton}
/>
),
};
When I click the icon I get the following error this.setstate is not a function 当我单击图标时,出现以下错误this.setstate不是函数
I think there is a naming problem. 我认为有一个命名问题。 I followed your link and the author there initializes the following state:
我遵循了您的链接,作者在那里初始化了以下状态:
constructor() {
super();
this.state = { TextInputDisableStatus: true }
}
In the onPress method, you are updating the status with: 在onPress方法中,您正在使用以下方式更新状态:
onPressButton = () => {
this.setState({ TextInputDisableStatus: false })
}
But then inside the TextInput the author and you are referring to 但是然后在TextInput内部,作者和您指的是
editable={this.state.TextInputDisableHolder}
this should probably be changed to: 这可能应该更改为:
editable={this.state.TextInputDisableStatus}
In addition you have to change: 此外,您还需要更改:
onPressButton() {
this.setState({ TextInputDisableStatus: false })
}
and: 和:
<Ionicons
style={{padding: 15}}
name={Platform.OS === 'ios' ? 'ios-create' : 'md-create'}
size={26}
onPress={() => this.onPressButton()}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.