【发布时间】:2017-04-26 09:30:30
【问题描述】:
我正在尝试创建一个以模式显示的表单。因此,当用户输入一个值时,该值将存储在本地存储中。这张图片可以帮助你理解我的意思:
这是表单的代码:
function FieldGroup({id, label, help, ...props}) {
return (
<ReactBootstrap.FormGroup controlId={id}>
<ReactBootstrap.ControlLabel>{label}</ReactBootstrap.ControlLabel>
<ReactBootstrap.FormControl {...props} />
{help && <ReactBootstrap.HelpBlock>{help}</ReactBootstrap.HelpBlock>}
</ReactBootstrap.FormGroup>
);
}
const formInstance = (
<form>
<FieldGroup
id="formControlsText"
type="text"
label="Text"
placeholder="Recipe Name"
inputRef={ref => { this.input = ref; }}
/>
<ReactBootstrap.FormGroup controlId="formControlsTextarea">
<ReactBootstrap.ControlLabel>Ingredients</ReactBootstrap.ControlLabel>
<ReactBootstrap.FormControl componentClass="textarea" placeholder="Enter Ingredients" />
</ReactBootstrap.FormGroup>
</form>
);
正如我在引导 React 教程中所读到的,我应该将<FormControl inputRef={ref => { this.input = ref; }} /> 添加到 FormControl 道具中。但是在添加它之后,当调用模态表单时出现错误:
【问题讨论】: