2
我目前实现Redux-Form以便将InputFields添加到我的应用程序。是否有办法手动关注子组件的输入?React专注于子组件输入
代码添加子组件:
<Field name="Quantity" ref="quantity" onKeyPress={(event) => this.handleKeyPress('inventory', event)} component={ InputField }/>
代码子组件:
render() {
const { input } = this.props;
const inputClass = classNames({ 'parsley-error': this.props.meta.touched && this.props.meta.error }, 'form-control')
return (
<div>
{this.props.meta.touched && this.props.meta.error && <span className="parsley-error-message">{this.props.meta.error}</span>}
<Input {...input} className={inputClass} onKeyPress={this.props.onKeyPress} standalone type="text" placeholder={this.props.placeholder}/>
</div>
)
}
当前实现企图焦点:
handleKeyPress(value, event){
if(event.charCode == 13){
this.refs["inventory"].getDOMNode().focus();
}
}
我硬编码为重点库存只为测试目的