[英]How to add or remove form keys using react-final-form
single config example shows what configuration I use for inputs.单个配置示例显示了我用于输入的配置。
export const age = [
{
value: '',
type: 'radio',
name: 'age',
items: [
{value: 'kid', label: 'Im less than 18',
{value: 'adult', label: 'Im 18!',
],
},
];
export const someDate = [
{
type: 'date',
value: null,
name: 'someDate',
label: 'Enter date',
format: 'dd/MM/yyyy',
minDate: new Date('2019-12-31'),
maxDate: new Date('2020-03-31'),
validators: required.required.date
}
];
RFForm is a wrapper for rect-final-form Form component and I pass all components inside as children. RFForm 是 rect-final-form Form 组件的包装器,我将所有组件作为子组件传入。
<RFForm
config={[...age, ...someDate, ...somethingElse]}
submit={submit}
>
<SectionBox title="Your age">
<Box mb={5}>
<InputList inputs={age}/>
</Box>
<SectionTitle title="Date"/>
<Box maxWidth="50%">
<InputList inputs={someDate}/>
</Box>
</SectionBox>
<SectionBox title="Something else">
<Box maxWidth="50%">
<InputList inputs={somethingElse}/>
</Box>
</SectionBox>
{
conditionToHideOrShowSection && <SectionWithInputs />
}
{
buttons
}
</RFForm>
I want to add a new section that will hide or show depends on what the user picks.我想添加一个新部分,该部分将根据用户选择的内容隐藏或显示。 The section should be ONLY present when the second radio button value is selected (adult).
该部分应仅在选择第二个单选按钮值(成人)时出现。 The section will contain a component with inputs from the configuration.
该部分将包含一个带有来自配置的输入的组件。 All the fields should be required.
所有字段都应该是必需的。 This should only be validated when the section is present.
这应该仅在该部分存在时进行验证。
Actually you have access to it, but in other way via render
method link实际上您可以访问它,但以其他方式通过
render
方法链接
This sample shows how to conditionally show inputs link .此示例展示了如何有条件地显示输入链接。 Be aware if input hide back the data won't gone, it's still there , so to cleanup you should use
change('inputName', undefined)
(at least it helps me in my case)请注意,如果输入隐藏数据不会消失,它仍然存在,因此要清理您应该使用
change('inputName', undefined)
(至少在我的情况下它对我有帮助)
At last you also should checkout about subscription
prop.最后,您还应该查看
subscription
道具。 link 关联
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.