如何在語義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