3

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.

Rallen
  • 2,240
  • 20
  • 22
gibelium
  • 101
  • 1
  • 6

3 Answers3

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
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.