为什么我所有的redux形式的复选框都已链接

时间:2018-07-26 22:18:46

标签: reactjs redux redux-form

我试图用redux-form创建一个表单,但是我遇到了一个问题,当我选中我的复选框之一时,它们都被选中了。

我已经在一个表单元素中创建了自己的复选框,该表单元素会像这样返回:

<div>
    <label>Content Type</label>
    {contentTypes.map(type=> {
        return(
            <Field
                label={type.name}
                name='content-type'
                component={this.renderField}
                content_type={type.type}
                type='checkbox'
                value='text'
            />
        )
    })}
</div>

renderField函数如下所示:

renderField({label, type, value, input, content_type}) {
    return(
        <div className='form-group'>
            <label>{label}</label>
            <input
                {...input}
                className='form-control'
                type={type}
                value={content_type}
                name={input.name}
            />
        </div>
    )
}

我换出了content_type的值,因为每次运行值都未定义。我对Redux Form来说是个新手,所以如果我做错了事,请告诉我。

1 个答案:

答案 0 :(得分:1)

name='content-type'

您需要为其赋予唯一的名称