I have a list of parameters that may be checked or not. Its correspondent fields are enabled/disabled in dependence of checkbox state. So I want to enable and validate field if parameter is checked, and disable field and turn off validation rule while checkbox is unchecked.
But I can't switch required
rule to false
while toggling checkbox.
As you see the registrations
parameter is unchecked but the field still have a validation..
Here is how I've done it:
<Row key={index} gutter={8}>
<Col span={6} offset={4}>
<Form.Item help="">
<Checkbox
checked={attribute.isActive}
disabled={isViewMode}
onChange={this.handleChangeAttributeActive(attribute.eventId)}
value={attribute.name}
>
{attribute.name}
</Checkbox>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item help="">
{getFieldDecorator(`${attribute.name}`, {
initialValue: attribute.attributeSendName,
rules: [{ required: attribute.isActive }],
})(
<Input
disabled={isViewMode || !attribute.isActive}
/>
)}
</Form.Item>
</Col>
</Row>
attributes
is an array of parameters that stores in component state.
Checkbox handler just switch to opposite isActive
property
Can you please help? Thank