-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(Form): 将 FQA 中的 【如何根据某个字段变化动态展示数据】 改为 【字段联动的表单示例】
- Loading branch information
Showing
2 changed files
with
53 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import Form from '../Form'; | ||
import Radio from '../../radio'; | ||
import Button from '../../button'; | ||
|
||
const { FormItem } = Form; | ||
|
||
export default function FormExample() { | ||
const [form] = Form.useForm(); | ||
const setMessage = () => { | ||
form.setFieldsValue({ | ||
type: 'cold', | ||
ice: '1', | ||
}); | ||
}; | ||
|
||
return ( | ||
<Form form={form} colon labelWidth={100}> | ||
<FormItem label="类型" name="type" initialData="hot"> | ||
<Radio.Group> | ||
<Radio value="hot">热饮</Radio> | ||
<Radio value="cold">冷饮</Radio> | ||
</Radio.Group> | ||
</FormItem> | ||
<FormItem shouldUpdate={(prev, next) => prev.type !== next.type}> | ||
{({ getFieldValue }) => { | ||
if (getFieldValue('type') === 'cold') { | ||
return ( | ||
<FormItem label="冰量" key="ice" name="ice"> | ||
<Radio.Group> | ||
<Radio value="0">正常冰</Radio> | ||
<Radio value="1">少冰</Radio> | ||
<Radio value="2">去冰</Radio> | ||
</Radio.Group> | ||
</FormItem> | ||
); | ||
} | ||
return null; | ||
}} | ||
</FormItem> | ||
|
||
<FormItem style={{ marginLeft: 100 }}> | ||
<Button onClick={setMessage}>选择冷饮-少冰</Button> | ||
</FormItem> | ||
</Form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters