如何使用 Redux-form 从复选框中获取值?

如何使用 Redux-form 从复选框中获取值?

问题描述:

如何将 redux 表单中复选框的默认布尔值更改为您在输入本身上指定的值?

How do you change the default boolean value for a checkbox in redux form to be the value you specify on the input itself?

例如,我有一个这样的输入:

For example, I have an input like this:

<input type="checkbox" value="页面丢失或乱序" {...issue1}/>

当 Redux 表单选择这个时,它只会给我一个真/假,即使我想要值页面丢失或乱序"

When Redux form picks this up, it just gives me a true/false, even though I want the value "Pages missing or out of order"

我可以做这样的事情来到达我需要去的地方,以便当表单提交时,它会提交值页面丢失或乱序,而不是真/假?

Can I do something like this to get where I need to go so that when the form submits, it will submit the value "Pages missing or out of order, instead of true/false?

console.log(value.target.value)} value="页面丢失或乱序"/>

当我删除 {...issue1} 时,将调用我的自定义 onChange 事件处理程序,但是当我保留 {...issue1} 时,它会被完全忽略.

when I remove the {...issue1}, my custom onChange event handler will be called, but when I keep {...issue1}, it's completely ignored.

想法?

不,redux-form 将复选框视为布尔值.您必须将布尔值映射到其他地方的字符串.

No, redux-form treats checkboxes as boolean values. You'll have to map the boolean to the string elsewhere.