4
redux-form
v7を使用すると、フィールド値を設定する方法がないことがわかります。今私のform
には2つのselect
コンポーネントがあり、最初のselect
コンポーネント値が変更されたときに2番目の値がクリアされます。クラスのプログラムでRedux-Formフィールド値を変更する
レンダリング:
<div className={classNames(style.line, style.largeLine)}>
<div className={style.lable}>site:</div>
<div className={style.content}>
<Field
name="site"
options={sites}
clearable={false}
component={this.renderSelectField}
validate={[required]}
/>
</div>
</div>
<div className={classNames(style.line, style.largeLine)}>
<div className={style.lable}>net:</div>
<div className={style.content}>
<Field
name="net"
options={nets}
clearable={false}
component={this.renderSelectField}
validate={[required]}
warning={warnings.net}
/>
</div>
</div>
今私はselect
changeフックを追加し、どのように私は他のselect
値に
renderSelectField = props => {
const {
input,
type,
meta: { touched, error },
...others
} = props
const { onChange } = input
const _onChange = value => {
onChange(value)
this.handleSelectChange({ value, type: input.name })
}
return (
<CHSelect
error={touched && error}
{...input}
{...others}
onChange={_onChange}
onBlur={null}
/>
)
}
おかげで多く、それが – taven
が、同時に複数のフィールドを設定するためのAPIがある素晴らしいですか! initialValues中ではない –