2022-04-29 20:48:10 +08:00
|
|
|
---
|
|
|
|
order: 3.1
|
|
|
|
title:
|
|
|
|
zh-CN: 表单禁用
|
|
|
|
en-US: Form disabled
|
2022-07-29 15:54:36 +08:00
|
|
|
version: 4.21.0
|
2022-04-29 20:48:10 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
设置表单组件禁用,仅对 antd 组件有效。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Set component disabled, only works for antd components.
|
|
|
|
|
|
|
|
```tsx
|
|
|
|
import React, { useState } from 'react';
|
2022-07-18 14:21:52 +08:00
|
|
|
import { PlusOutlined } from '@ant-design/icons';
|
2022-04-29 20:48:10 +08:00
|
|
|
import {
|
|
|
|
Form,
|
|
|
|
Input,
|
|
|
|
Button,
|
|
|
|
Radio,
|
|
|
|
Select,
|
|
|
|
Cascader,
|
|
|
|
DatePicker,
|
|
|
|
InputNumber,
|
|
|
|
TreeSelect,
|
|
|
|
Switch,
|
|
|
|
Checkbox,
|
2022-07-18 14:21:52 +08:00
|
|
|
Upload,
|
2022-04-29 20:48:10 +08:00
|
|
|
} from 'antd';
|
|
|
|
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
const { TextArea } = Input;
|
|
|
|
|
|
|
|
const FormDisabledDemo = () => {
|
|
|
|
const [componentDisabled, setComponentDisabled] = useState<boolean>(true);
|
|
|
|
const onFormLayoutChange = ({ disabled }: { disabled: boolean }) => {
|
|
|
|
setComponentDisabled(disabled);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-07-29 15:54:36 +08:00
|
|
|
<>
|
|
|
|
<Checkbox checked={componentDisabled} onChange={e => setComponentDisabled(e.target.checked)}>
|
|
|
|
Form disabled
|
|
|
|
</Checkbox>
|
|
|
|
<Form
|
|
|
|
labelCol={{ span: 4 }}
|
|
|
|
wrapperCol={{ span: 14 }}
|
|
|
|
layout="horizontal"
|
|
|
|
onValuesChange={onFormLayoutChange}
|
|
|
|
disabled={componentDisabled}
|
|
|
|
>
|
|
|
|
<Form.Item label="Chekbox" name="disabled" valuePropName="checked">
|
|
|
|
<Checkbox>Checkbox</Checkbox>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Radio">
|
|
|
|
<Radio.Group>
|
|
|
|
<Radio value="apple"> Apple </Radio>
|
|
|
|
<Radio value="pear"> Pear </Radio>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Input">
|
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Select">
|
|
|
|
<Select>
|
|
|
|
<Select.Option value="demo">Demo</Select.Option>
|
|
|
|
</Select>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="TreeSelect">
|
|
|
|
<TreeSelect
|
|
|
|
treeData={[
|
|
|
|
{ title: 'Light', value: 'light', children: [{ title: 'Bamboo', value: 'bamboo' }] },
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Cascader">
|
|
|
|
<Cascader
|
|
|
|
options={[
|
|
|
|
{
|
|
|
|
value: 'zhejiang',
|
|
|
|
label: 'Zhejiang',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'hangzhou',
|
|
|
|
label: 'Hangzhou',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="DatePicker">
|
|
|
|
<DatePicker />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="RangePicker">
|
|
|
|
<RangePicker />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="InputNumber">
|
|
|
|
<InputNumber />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="TextArea">
|
|
|
|
<TextArea rows={4} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Switch" valuePropName="checked">
|
|
|
|
<Switch />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Upload" valuePropName="fileList">
|
|
|
|
<Upload action="/upload.do" listType="picture-card">
|
|
|
|
<div>
|
|
|
|
<PlusOutlined />
|
|
|
|
<div style={{ marginTop: 8 }}>Upload</div>
|
|
|
|
</div>
|
|
|
|
</Upload>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item label="Button">
|
|
|
|
<Button>Button</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
</>
|
2022-04-29 20:48:10 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => <FormDisabledDemo />;
|
|
|
|
```
|