在onSubmitEditing之后如何关注相同的输入?

时间:2017-10-24 16:03:32

标签: forms react-native

我希望在onSubmitEditing函数之后再次关注相同的输入。但还没有实现。任何帮助将不胜感激。

这是我的代码:

cabArticleLocal.createOrReplaceTempView("tempTable")
sqlContext.sql("select row_number() over (order by article_id) as id,is_enabled,cab_article,article_id from tempTable")

我知道如何通过按钮或其他输入字段提交。但我不能用相同的输入做到这一点。

2 个答案:

答案 0 :(得分:2)

噢,我多么傻。只需将以下行添加到TextInput即可。

blurOnSubmit={false}

答案 1 :(得分:0)

根据Docs,它声明:

  

通过原生元素公开的两种方法是.focus().blur(),它们会以编程方式聚焦或模糊TextInput

因此,这应该有效:

// create your ref object somewhere global
let barcode: Input;

// then this should work
<Input
       ref={this.barcode}
       style={styles.barcodeInput}
       autoFocus={true}
       onChangeText={(text) => {
          this.setState({barcodeNumber: text});
       }}
       onSubmitEditing={(event)=> {
          this.getResult();
          this.barcode.focus();
       }}
       placeholder='Barcode Number'/>

getResult(){
    if ( this.state.barcodeNumber === '021200507878' ){
        this.setState({backgroundColor: '#2ecc71', status:'success'});//green

    } else {
        this.setState({backgroundColor: '#c0392b', status:'error'}); //red
    }

    this.clearText('barcode');
}

clearText(fieldName) {

   this.refs[fieldName].setNativeProps({text: ''});
}