-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from alibaba/dev
form-render 1.0.2 -> 1.0.5
- Loading branch information
Showing
37 changed files
with
659 additions
and
185 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
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,105 @@ | ||
```jsx | ||
import React, { useEffect } from 'react'; | ||
import { Button } from 'antd'; | ||
import FormRender, { useForm } from 'form-render'; | ||
|
||
const schema = { | ||
displayType: 'row', | ||
type: 'object', | ||
properties: { | ||
input1: { | ||
title: '简单输入框简单输入框', | ||
description: 'sdfdsgfshfghfgdh', | ||
type: 'string', | ||
required: true, | ||
rules: [ | ||
{ | ||
required: true, | ||
message: 'ete', | ||
}, | ||
], | ||
}, | ||
input2: { | ||
title: '简单输入框2', | ||
type: 'boolean', | ||
}, | ||
input3: { | ||
title: '简单输入框3', | ||
type: 'string', | ||
required: true, | ||
}, | ||
image: { | ||
title: '图片展示', | ||
type: 'string', | ||
format: 'image', | ||
}, | ||
checkboxes: { | ||
title: '多选', | ||
description: '下拉多选', | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
enum: ['A', 'B', 'C', 'D'], | ||
enumNames: ['杭州', '武汉', '湖州', '贵阳'], | ||
widget: 'checkboxes', | ||
default: null, | ||
}, | ||
multiSelect: { | ||
title: '多选', | ||
description: '下拉多选', | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
enum: ['A', 'B', 'C', 'D'], | ||
enumNames: ['杭州', '武汉', '湖州', '贵阳'], | ||
widget: 'multiSelect', | ||
default: null, | ||
}, | ||
}, | ||
}; | ||
|
||
const Demo = () => { | ||
const form = useForm(); | ||
useEffect(() => { | ||
form.setValues({ a: 1, b: 2, c: { x: { y: [{ z: 'sdf' }] } } }); | ||
}, []); | ||
const onFinish = (formData, errorFields) => { | ||
if (errorFields.length > 0) { | ||
alert( | ||
'errorFields:' + | ||
JSON.stringify(errorFields) + | ||
'\nformData:' + | ||
JSON.stringify(formData, null, 2) | ||
); | ||
} else { | ||
alert('formData:' + JSON.stringify(formData, null, 2)); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<FormRender | ||
// debugCss | ||
validateMessages={{ required: '213' }} | ||
form={form} | ||
schema={schema} | ||
onFinish={onFinish} | ||
/> | ||
<Button type="primary" onClick={form.submit}> | ||
提交 | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Demo; | ||
``` | ||
|
||
label, descIcon | ||
入参 | ||
随便传入什么值,都会透传,不会被 schema 截取 | ||
null 值在多选里的展示 | ||
|
||
title 的布局需要重新写一下 |
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,69 @@ | ||
```jsx | ||
import React, { useEffect } from 'react'; | ||
import { Button, Modal } from 'antd'; | ||
import FormRender, { useForm } from 'form-render'; | ||
|
||
const delay = ms => new Promise(res => setTimeout(res, ms)); | ||
|
||
const schema = { | ||
type: 'object', | ||
properties: { | ||
inputName: { | ||
bind: 'ttt', | ||
title: '简单输入框', | ||
type: 'string', | ||
format: 'image', | ||
}, | ||
listName: { | ||
bind: 'a.x', | ||
title: '对象数组', | ||
description: '对象数组嵌套功能', | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
inputName2: { | ||
title: '复杂输入框', | ||
description: '英文或数字组合', | ||
type: 'string', | ||
}, | ||
selectName: { | ||
title: '单选', | ||
type: 'string', | ||
enum: ['a', 'b', 'c'], | ||
enumNames: ['早', '中', '晚'], | ||
widget: 'radio', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const Demo = () => { | ||
const form = useForm(); | ||
|
||
useEffect(() => { | ||
form.setValues({ ttt: '234', a: { x: [{ inputName2: 'hello' }] } }); | ||
}, []); | ||
|
||
const onFinish = (formData, errorFields) => { | ||
if (errorFields.length > 0) { | ||
alert('errorFields:' + JSON.stringify(errorFields)); | ||
} else { | ||
alert('formData:' + JSON.stringify(formData, null, 2)); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<FormRender form={form} schema={schema} onFinish={onFinish} /> | ||
<Button type="primary" onClick={form.submit}> | ||
提交 | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Demo; | ||
``` |
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,87 @@ | ||
```jsx | ||
import React from 'react'; | ||
import { Button } from 'antd'; | ||
import FormRender, { useForm } from 'form-render'; | ||
|
||
const schema = { | ||
displayType: 'row', | ||
labelWidth: 120, | ||
type: 'object', | ||
properties: { | ||
input1: { | ||
title: '简单输入框', | ||
description: | ||
'sdfasdgdsgfdsgfsdfgssdgdsgfdsgfsdfgssdgdsgfdsgfsdfgsdfgsdfgfghfghfghfgh', | ||
type: 'string', | ||
required: true, | ||
}, | ||
input2: { | ||
title: '简单输入框2', | ||
type: 'boolean', | ||
}, | ||
daaa: { | ||
title: 'daa', | ||
type: 'string', | ||
format: 'date', | ||
props: { | ||
showTime: true, | ||
format: 'dateTime', | ||
}, | ||
}, | ||
daaa2: { | ||
title: 'daa2', | ||
type: 'string', | ||
format: 'time', | ||
}, | ||
daaa3: { | ||
title: 'daa3', | ||
type: 'range', | ||
format: 'date', | ||
}, | ||
input3: { | ||
title: '图片', | ||
type: 'string', | ||
format: 'image', | ||
required: true, | ||
}, | ||
input4: { | ||
title: 'url', | ||
type: 'string', | ||
format: 'url', | ||
required: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const Demo = () => { | ||
const form = useForm(); | ||
const onFinish = (formData, errorFields) => { | ||
if (errorFields.length > 0) { | ||
alert( | ||
'errorFields:' + | ||
JSON.stringify(errorFields) + | ||
'\nformData:' + | ||
JSON.stringify(formData, null, 2) | ||
); | ||
} else { | ||
alert('formData:' + JSON.stringify(formData, null, 2)); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<FormRender | ||
debugCss={false} | ||
form={form} | ||
schema={schema} | ||
onFinish={onFinish} | ||
/> | ||
<Button type="primary" onClick={form.submit}> | ||
提交 | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Demo; | ||
``` |
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,9 @@ | ||
--- | ||
order: 5 | ||
group: | ||
order: 3 | ||
title: 高级用法 | ||
toc: false | ||
--- | ||
|
||
# 表单校验 |
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
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
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
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
Oops, something went wrong.