如何使用semantic-ui-redux-form-fields设置initialValue

问题描述 投票:0回答:1

我正在尝试使用semantic-ui-redux-form-fields创建一个编辑表单。表单工作正常,空白起点,但对于我有初始值的编辑表单,我无法使其工作。

如果我使用直接redux-form,只要我有prop传递到我的表单组件中,initialValuesField#component就可以正常初始化表单。

使用该逻辑,我认为我需要做的就是将"input"属性从{Input}更改为currentValue(/ w相应的导入)。请注意,我从未看到props通过{initialValues: {"first_name": "Bob"}} 传入。目前尚不清楚这个道具将如何填充。

道具:

import { Form, Button } from 'semantic-ui-react'
import { reduxForm, Field} from 'redux-form'

...

return <Field component="input" type="text" name='first_name'/>

工作部分:

import { Form, Button } from 'semantic-ui-react'
import { reduxForm, Field} from 'redux-form'
import { Input } from 'semantic-ui-redux-form-fields'

...

return <Field component={Input} type="text" name='first_name'
              currentValue={this.props.currentValue}/>

不工作组件:

Input
redux-form semantic-ui-react semantic-ui-redux-form-fields
1个回答
1
投票

semantic-ui-react中的defaultValue组件有一个Field道具,我相信你应该能够使用数据初始化Input,因为你传递component在它的<Field component={Input} defaultValue={this.props.currentValue} name='first_name' type='text' /> 道具。

qazxswpoi
© www.soinside.com 2019 - 2024. All rights reserved.