I have an antd form with multiple form items and try to find a way to mark the complete form as readonly. I could for sure set each input component to 'disabled' but I wonder if there is a convenient way to do so on the form via an API call that I do not know yet.
Asked
Active
Viewed 3,548 times
3 Answers
3
Wrapping the antd form inside a fieldset and setting this to 'disabled' works pretty well.
<fieldset disabled={editorDisabled}>
<Form>
...
<Form/>
<fieldset/>

gibelium
- 101
- 1
- 6
-
1I saw this at https://stackoverflow.com/a/36216001 but I think it is only for html – k1eran Oct 14 '20 at 22:53
-
1Not work with select, datepicker – Fiodorov Andrei Feb 07 '22 at 11:34
1
I don't see such an option in the form api, and I think it's the rare use case, so I doubt it exists. However, you can simply add variable which will track the disabled
status, i.e.:
const YourAwesomeComponent = (props) => {
const disabled = someLogicToCalculateTheDisabledStatus(props);
return <Form ...>
<Input disabled={disabled} ... />
<Select disabled={disabled} ... />
<Button disabled={disabled} ... />
</Form>
}
Hope it helps.

Alejandro
- 5,834
- 1
- 19
- 36
0
As of version 4.21.0 (Jun 6, 2022) the disabled prop can be used in the form to disable all fields, i.e.:
<Form disabled={true}>
...
</Form>
It is enforced as long as a <Form.Item/>
isn't explicitly marked as not disabled with disabled={false}
. You can see the reference in antd docs here.

Babis Skeparnakos
- 34
- 1
- 7