输入后如何自动提交文本?
How do I autosubmit text after entry?
我想知道处理自动提交用户输入的代码的最佳方法是什么?到目前为止我有这个但是我不知道这是否有效。我尝试对其进行测试,但没有达到预期的效果。
This is the form control:
<div className="form-group">
<input
type="tel"
autoComplete="one-time-code"
maxLength="6"
className="code-form"
onChange={this.changeCode}
value={code}
/>
</div>
这是 onChange 事件:
changeCode = e => {
this.setState({ code: e.target.value });
if(this.verificationCode.length == 6) {
this.verifyCode();
}
};
如果用户输入的长度是6,那我就提交。这是正确的做法吗?
以下代码位于 react-native 应用程序内的 webview react 项目中。
你可以试试油门和去抖:
if (this.verificationCode.length < 5) {
throttle(500, this.verifyCode)
} else {
debounce(500, this.verifyCode);
}
这么小的任务不需要debouncing,只需要检查setState回调中的代码长度并提交即可。
changeCode = e => {
this.setState({ code: e.target.value },()=>{
if(this.state.code.length == 6) {
this.verifyCode();
}
});
};
我想知道处理自动提交用户输入的代码的最佳方法是什么?到目前为止我有这个但是我不知道这是否有效。我尝试对其进行测试,但没有达到预期的效果。
This is the form control:
<div className="form-group">
<input
type="tel"
autoComplete="one-time-code"
maxLength="6"
className="code-form"
onChange={this.changeCode}
value={code}
/>
</div>
这是 onChange 事件:
changeCode = e => {
this.setState({ code: e.target.value });
if(this.verificationCode.length == 6) {
this.verifyCode();
}
};
如果用户输入的长度是6,那我就提交。这是正确的做法吗?
以下代码位于 react-native 应用程序内的 webview react 项目中。
你可以试试油门和去抖:
if (this.verificationCode.length < 5) {
throttle(500, this.verifyCode)
} else {
debounce(500, this.verifyCode);
}
这么小的任务不需要debouncing,只需要检查setState回调中的代码长度并提交即可。
changeCode = e => {
this.setState({ code: e.target.value },()=>{
if(this.state.code.length == 6) {
this.verifyCode();
}
});
};