Skip to content

Commit

Permalink
fix: 修复 deFormat 对数据处理失效
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Aug 27, 2020
1 parent d213824 commit 5972e6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions docs/examples/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const Demo = () => {
scenes={{ diff }}
>
{[
{
type: 'input',
label: '支持多层对象',
name: ['first', 'second'],
deFormat: (value) => `${value || ''} first 为 undefined `,
},
{
type: 'input',
label: 'immutable',
Expand Down
2 changes: 1 addition & 1 deletion packages/yforms/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yforms",
"version": "1.3.0",
"version": "1.3.1",
"description": "自定义表单组件",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
13 changes: 5 additions & 8 deletions packages/yforms/src/YForm/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,11 @@ const InternalForm = React.memo<YFormProps>((thisProps) => {
const parentValue = getParentNameData(_initialValues, name);
const value = format(get(_initialValues, name), parentValue, _initialValues);
if (!find(formatRef.current, { name })) {
// 如果上一级是 undefined,则不处理该字段。(List add 会生成空对象)
if (parentValue !== undefined) {
form.setFields([{ name, value }]);
formatRef.current.push({ name, value });
// 初始化使用 deFormat 后的数据
set(deFormatValues, name, value);
onDeFormatFieldsValue([{ name, format }]);
}
form.setFields([{ name, value }]);
formatRef.current.push({ name, value });
// 初始化使用 deFormat 后的数据
set(deFormatValues, name, value);
onDeFormatFieldsValue([{ name, format }]);
}
},
[_initialValues, form, deFormatValues, onDeFormatFieldsValue],
Expand Down

0 comments on commit 5972e6f

Please sign in to comment.