【问题标题】:TextInput Enter SpaceTextInput 输入空格
【发布时间】:2019-05-17 23:26:25
【问题描述】:

我正在开发 React 原生应用。使用 TextInput 作为名字或姓氏。在空的 textInput 框中的文本输入上输入空格按钮时,TextInput 为空。然后我将检查 textInput 是否为 Empty。他在 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

【问题讨论】:

  • 您可以使用修剪功能。 if(this.state.firstName.trim() == '')

标签: javascript reactjs react-native


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-24
相关资源
最近更新 更多