如何在语义UI反应中的Form.Input或Input组件上设置预定义的值?我试过将defaultValue =“someVal”作为一个可以工作的道具。但是如果道具改变,那不会更新价值。我尝试传递预填充它的prop value =“someVal”,但阻止任何访问来编辑该字段。所有击键都被忽略。必须有办法基本上做使用语义UI预填充输入文本
并仍然有更新componentWillReceiveProps触发时的值?
这里是我使用
输入组件这是使用以下输入作为控制形式 https://react.semantic-ui.com/collections/form https://react.semantic-ui.com/elements/input
我有一个AutoSaveInput.jsx其基本上使下面与输入一个onChange自动保存每个按键(仍然需要添加一个去抖动)。
<Label basic>{this.props.label}</Label>
<Form.Input
defaultValue={this.props.defaultValue}
disabled={this.props.disabled}
name={this.props.name}
onChange={this.onChange}
error={this.state.isDirty}
/>
上面的输入最初工作正常。但是,当新的道具进来时,this.props.label更新正常,但Form.Input值根本不会更新。相反,它仍然显示以前的值。
此外,如果我改变它到下面,值会更新新的道具,但你不能输入输入本身。游标只是跳到输入的末尾,不让你输入其他的东西。
<Label basic>{this.props.label}</Label>
<Form.Input
value={this.props.defaultValue}
disabled={this.props.disabled}
name={this.props.name}
onChange={this.onChange}
error={this.state.isDirty}
/>
此外道具正在通过ReactRouter v4更新通过点击一个点击,其中var是什么加载在不同的窗体内容进行编辑。
你可以发布你使用它的组件吗?上下文会有很大的帮助。听起来很容易,但你应该将它设置为一个受控输入,其值设置为一个道具值和一个更新该道具的onChange。 –
有一个onChange功能。例如,'onChange((e)=> this.state.data.input_name))' – fungusanthrax