我正在开发React本机应用程序。使用TextInput作为名字或姓氏。当在空白textInput框上输入文本时输入空格按钮时,TextInput为空。然后,我将检查是否为空。他在textInput上显示了一些价值。但是我没有在textinput上输入任何值或仅输入空格。我认为他将空间视为角色。因此,请帮助我检查这种情况。
<TextInput
placeholder="Joe"
autoFocus={false}
returnKeyType={"next"}
blurOnSubmit={false}
onChangeText={firstName => this.setState({ firstName })}
onSubmitEditing={(event) => {this.passTextInput1.focus()}}
style={styles.textBox1} />
<TextInput
placeholder="Bloggs"
inputRef={(input) => {this.passTextInput1 = input}}
returnKeyType={"next"}
onChangeText={lastName => this.setState({ lastName })}
onSubmitEditing={(event) => this.onValidations()}
style={styles.textBox2} />
Condition:
if(this.state.firstName == '' && this.state.lastName == ''){
Alert.alert('Please fill the required fields')
} else if(this.state.firstName == '') {
Alert.alert('Please fill the First Name')
} else if(this.state.lastName == '') {
Alert.alert('Please fill the Last Name')
} else {
this.props.navigation.navigate('AccountStep2', {
Firstname: this.state.firstName,
Lastname: this.state.lastName,
})
}
Textinput Check empty or not. when textInput is empty. when click on space button. than check condition he show some value on textinput
答案 0 :(得分:1)