From 0a8fd44816d9f1985f60a3a7528fd04a1c602a7c Mon Sep 17 00:00:00 2001 From: Rairn <958414905@qq.com> Date: Tue, 25 Apr 2023 16:17:14 +0800 Subject: [PATCH] fix: fix error with setting default value for date type --- .../src/schema-component/antd/form-item/FormItem.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index 76c1cecddc..b4d8499478 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -4,6 +4,7 @@ import { Field } from '@formily/core'; import { ISchema, Schema, observer, useField, useFieldSchema } from '@formily/react'; import { uid } from '@formily/shared'; import _ from 'lodash'; +import moment from 'moment'; import React, { useContext, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { ACLCollectionFieldProvider } from '../../../acl/ACLProvider'; @@ -688,5 +689,9 @@ function isFileCollection(collection: Collection) { FormItem.FilterFormDesigner = FilterFormDesigner; export function getFieldDefaultValue(fieldSchema: ISchema, collectionField: CollectionFieldOptions) { - return fieldSchema?.default || collectionField?.defaultValue; + const result = fieldSchema?.default || collectionField?.defaultValue; + if (collectionField?.uiSchema?.['x-component'] === 'DatePicker' && result) { + return moment(result); + } + return result; }