React-bootstrap表单只允许我在value设置为this.state.value时输入
React-bootstrap form only lets me type if value is set to this.state.value?
我是第一次使用react-bootstrap,我试图使用这里讨论的表单组件https://react-bootstrap.github.io/components.html#forms
目前在我的组件中,我的代码是这样的:
<form>
<FormGroup controlId="formEmail" >
<ControlLabel>Email</ControlLabel>
<FormControl
type="text"
value={this.state.loginInput.email}
placeholder="Email"
/>
</FormGroup>
<FormGroup controlId="formPassword" >
<ControlLabel>Password</ControlLabel>
<FormControl
type="text"
value={this.state.loginInput.password}
placeholder="Password"
/>
</FormGroup>
</form>
根据real -bootstrap页面上的说明,表单完全按照预期正确地呈现,但是当我尝试键入输入时,什么也没有发生。如果我将以下行从value={this.state.loginInput.password}
更改为value={this.state.value}
,我只能在输入中输入
如果我试图使this.state.value
变成value
以外的任何东西,它将不起作用。我的构造函数看起来像这样:
constructor(props) {
super(props);
this.state = {
showModal: false,
loginInput: {
email: '',
password: '',
},
};
有一个原因反应引导不让我使用我自己的值吗?
解决方案似乎是FormControl
要求我有一个OnChange
函数,否则输入字段是只读的?这似乎是奇怪的行为,但仅仅改变我的表单有一个onChange事件定义允许表单工作如预期。
<FormGroup controlId="formPassword" >
<ControlLabel>Password</ControlLabel>
<FormControl
type="text"
value={this.state.loginInput.password}
placeholder="Password"
onChange={this.handleChange}
/>
</FormGroup>
相关文章:
- 将php值传递给点击(getFunction(this.value))问题
- Javascript:this.value 函数不起作用
- Javascript onchange(this.value,this.value)在ipad上不起作用
- this.value在<td>标记显示未定义
- 从javascript insertCell HTML输入标记传递this.value
- 为什么我需要将“var value = val;”更改为“this.value = val;”,这样我就不会收到“未定义
- JQuery 将输入框值设置为 this.value onclick
- this.value 在从 onchange 事件调用函数时显示为 undefind
- 将 this.value 传递给 JS 中的函数,然后更改该值
- 流星:如何使用模板事件检索“{{this}}-value”
- javascript this.value没有'不起作用
- this.value 返回带有值的括号
- AngularJS-将this.value传递到函数中
- 什么是'this.value'经典ASP Javascript参考中的平均值
- onkeyup="this.value = this.value.replace(/,/g,'.
- HTML表单,onclick="this.disabled=true;this.value='发送中,
- JavaScript- this value
- React-bootstrap表单只允许我在value设置为this.state.value时输入
- 在requestAnimationFrame中设置正确的this-value
- 未捕获类型错误:不能使用'in'操作符“;使用value $(this)