Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnIsOnTheRoad committed Jul 14, 2020
2 parents 658e029 + e27dd8c commit d7941b8
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 58 deletions.
102 changes: 51 additions & 51 deletions docs/zh-cn/schema-develop/form-state.md

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions docs/zh-cn/schema-develop/form-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,56 @@ ReactDOM.render(<App />, document.getElementById('root'))
- 先点击刷新,后点击重置,点击刷新的时候,initialValues 受表单重渲染而重新更新,aa 字段的初始值更新了,但是因为 aa 当前是有值状态,所以不会被默认值更新所影响
- 先点击刷新,后点击重置,点击重置按钮的时候,默认是会将值变为初始值,因为初始值变了,所以 aa 字段的值也变了,如果不希望出现这种行为,可以给重置按钮配置强制清空
- 交替点击清空和刷新按钮,可以重复赋值,是因为初始值一直在变,清空使得字段又恢复到无默认值状态,所以是可以持续赋值的,看着就像前面 value 的效果一样

# InitialValues 覆盖 default

```jsx
import React, { useState } from 'react'
import ReactDOM from 'react-dom'
import {
SchemaForm,
SchemaMarkupField as Field,
FormButtonGroup,
Reset
} from '@formily/antd'
import { Input } from '@formily/antd-components'
import { Button } from 'antd'
import Printer from '@formily/printer'
import 'antd/dist/antd.css'

const App = () => {
const [value, setValue] = useState({
aa: 'first render value'
})
return (
<Printer>
<SchemaForm
initialValues={value}
components={{
Input
}}
>
<Field type="string" name="aa" x-component="Input" default="123" />
<Field type="string" name="bb" x-component="Input" default="321" />
<FormButtonGroup>
<Button
onClick={() => {
setValue({
aa: Math.random() * 1000 + '',
bb: Math.random() * 1000 + ''
})
}}
>
刷新
</Button>
<Reset>重置</Reset>
<Reset forceClear>清空</Reset>
</FormButtonGroup>
</SchemaForm>
</Printer>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
```

如果字段从未被修改过值,initialValues 会覆盖 default 属性的值,如果已经修改过值,那么无法覆盖
Loading

0 comments on commit d7941b8

Please sign in to comment.