Ask Your Question
1

How can one make antd form.setFieldsValue render when Form.Item has multiple elements?

asked 2023-05-28 21:59:09 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-28 22:25:01 +0000

huitzilopochtli gravatar image

You can use the dependencies prop of Form.Item to specify which fields/props the item depends on. This will ensure that form.setFieldsValue is triggered when any of the dependencies change.

For example, if you have a Form.Item with multiple elements such as Input and Checkbox, you can set the dependencies prop to an array containing the field names of both elements:

<Form.Item
  label="My Field"
  dependencies={['myInput', 'myCheckbox']}
>
  <Input name="myInput" />
  <Checkbox name="myCheckbox">Check me</Checkbox>
</Form.Item>

Now, when you call form.setFieldsValue to update the value of either myInput or myCheckbox, the Form.Item will be re-rendered and the updated value will be displayed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-28 21:59:09 +0000

Seen: 9 times

Last updated: May 28 '23