首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下一步和进入形式不要工作(反应本土和本土基础)

下一步和进入形式不要工作(反应本土和本土基础)
EN

Stack Overflow用户
提问于 2017-12-19 16:00:28
回答 3查看 1.7K关注 0票数 2

我正在使用native-base的表单来处理用户的用户名和密码。

当我按下键盘上的 next go时,它不会将光标移动到下一个或不提交输入。我们怎么才能解决这个问题?

代码语言:javascript
复制
import { Form } from 'native-base';
<Form style={styles.formStyle}>
    <AuthFieldInput
        placeholder="Username or Email"
        value={this.state.username}
        onChangeText={username => this.setState({username})}
        returnKeyType="next"/>
    <AuthFieldInput
        placeholder="Password"
        value={this.state.password}
        onChangeText={password => this.setState({password})}
        secureTextEntry
        returnKeyType="go"/>
</Form>

以下是<AuthField>呈现函数

代码语言:javascript
复制
import { Item, Label, Input, Text } from 'native-base';
<Item>
  <Input
    value={value}
    onChangeText={onChangeText}
    placeholder={placeholder}
    autoCorrect={false}
    secureTextEntry={secureTextEntry}
    returnKeyType={returnKeyType}
  />
</Item>

谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-12-19 18:33:53

这基本上是React的TextInput包装器,如果您想要做的是在按下"next“按钮时,转到另一个输入,您应该执行以下操作。

代码语言:javascript
复制
// <AuthField> render function
<Item>
    <Input
        value={value}
        onChangeText={onChangeText}
        placeholder={placeholder}
        autoCorrect={false}
        secureTextEntry={secureTextEntry}
        returnKeyType={returnKeyType}
        { ...this.props }
    />
</Item>

在组件中,您可以这样使用它:

代码语言:javascript
复制
// Other render
<Form style={styles.formStyle}>
    <AuthFieldInput
        placeholder="Username or Email"
        value={this.state.username}
        onChangeText={username => this.setState({username})}
        returnKeyType="next"
        onSubmitEditing={() => { 
            this.refs.passwowrd.focus(); 
        }}
    />
    <AuthFieldInput
        ref='password'
        placeholder="Password"
        value={this.state.password}
        onChangeText={password => this.setState({password})}
        secureTextEntry
        returnKeyType="go"
        />
</Form>

更新:请查看有关此功能的文档https://facebook.github.io/react-native/docs/textinput.html#onsubmitediting

票数 2
EN

Stack Overflow用户

发布于 2018-08-26 10:44:30

我收到了错误,因为"_this2.refs.password.focus“不是onSubmitEditing of TextInput上的一个函数。

我就是这样修好的:

  • 本机基“^2.4.2”升级到本机基“^2.7.1”的包。
  • 共享下面的示例代码:

代码语言:javascript
复制
<Item floatingLabel>
  <Label>Mobile Number</Label>
  <Input
    onChangeText = {(phone) => this.setState({phone})}
    value = {this.state.phone}
    autoCapitalize="none"
    keyboardType='numeric'
    returnKeyType={"next"}
    maxLength = {10}
    onSubmitEditing={(event) => this._password._root.focus()}
  />
</Item>

<Item floatingLabel>
  <Label>Password</Label>
  <Input
    getRef={(c) => this._password = c}
    onChangeText = {(password) => this.setState({password})}
    value={this.state.password}
    autoCapitalize="none"
    returnKeyType={"done"}
    secureTextEntry={this.state.hiddenPassword}
    onSubmitEditing = {this.handleLogin}
  />
</Item>

<TouchableOpacity>
  <Button style={styles.Button}
    onPress={this.handleLogin.bind(this)}>
    <Text style={styles.buttonText}>
      LOGIN
    </Text>
  </Button>
</TouchableOpacity>

票数 4
EN

Stack Overflow用户

发布于 2017-12-19 16:41:11

这些返回类型似乎不这样做。这一问题也曾被问到:

React Native: How to select the next TextInput after pressing the "next" keyboard button?

也许这对你有帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47890758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档