【发布时间】:2019-08-31 12:03:41
【问题描述】:
我正在使用react-final-form 并从这个示例中获得帮助
https://codesandbox.io/s/52q597j2p
在上面的例子中,当用户unchecked这个字段Is this a gift?时,giftCardMessage属性被从对象中移除
重现的步骤。
- 选中
Is this a gift?字段并在文本字段中输入Message。然后未选中的see属性将被删除。
我使用了上述概念并尝试做同样的事情。但在我的示例中,我使用了 prefixed。在我的示例中,如果我取消选中复选框,它不会删除对象的属性
https://codesandbox.io/s/react-final-form-declarative-form-rules-uvz6y
<WhenFieldChanges
field="gift"
becomes={false}
set="giftCardMessage"
to={undefined}
/>
<FieldPrefix prefix="apps.dh">
<div>
<label>Is this a gift?</label>
<PrefixedField name="gift" component="input" type="checkbox" />
</div>
<div>
<label>Message</label>
<PrefixedField
name="giftCardMessage"
component="textarea"
placeholder="What do you want the card to say?"
/>
</div>
</FieldPrefix>
【问题讨论】:
标签: javascript reactjs react-context react-final-form