From 43a45b7c996c84f19d00cb9754277b943daf9a10 Mon Sep 17 00:00:00 2001
From: Vben <anncwb@126.com>
Date: 星期日, 07 三月 2021 23:37:57 +0800
Subject: [PATCH] fix(form): ensure that the Form component does not verify hidden form items

---
 src/components/Form/src/components/FormItem.tsx |    6 +++++-
 src/views/demo/system/account/account.data.ts   |    2 +-
 CHANGELOG.zh_CN.md                              |    2 ++
 src/components/Form/src/hooks/useFormEvents.ts  |    1 +
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md
index 4e0a131..0dbd885 100644
--- a/CHANGELOG.zh_CN.md
+++ b/CHANGELOG.zh_CN.md
@@ -4,6 +4,7 @@
 
 - `BasicTree` 鏂板`clickRowToExpand`,鐢ㄤ簬鍗曞嚮鏍戣妭鐐瑰睍寮�
 - 鏂板 SvgIcon 鎻掍欢鍙婄ず渚�
+- 璐﹀彿绠$悊鐣岄潰澧炲姞宸︿晶閮ㄩ棬鏍�
 
 ### 鈿� Performance Improvements
 
@@ -22,6 +23,7 @@
 - 淇璐﹀彿绠$悊鏂板鏈竻绌烘棫鏁版嵁
 - form 缁勪欢搴斿厑璁� setFieldsValue 鏂规硶鍊间负 null 鎴栬�� undefined
 - 纭繚鍗曠骇闈㈠寘灞戞纭烦杞�
+- 纭繚 Form 缁勪欢涓嶆牎楠岄殣钘忕殑琛ㄥ崟椤�
 
 ## 2.0.2 (2021-03-04)
 
diff --git a/src/components/Form/src/components/FormItem.tsx b/src/components/Form/src/components/FormItem.tsx
index e2b6223..a2416a8 100644
--- a/src/components/Form/src/components/FormItem.tsx
+++ b/src/components/Form/src/components/FormItem.tsx
@@ -97,7 +97,7 @@
       return disabled;
     });
 
-    function getShow() {
+    function getShow(): { isShow: boolean; isIfShow: boolean } {
       const { show, ifShow } = props.schema;
       const { showAdvancedButton } = props.formProps;
       const itemIsAdvanced = showAdvancedButton
@@ -151,6 +151,10 @@
       const { rulesMessageJoinLabel: globalRulesMessageJoinLabel } = props.formProps;
       if (requiredRuleIndex !== -1) {
         const rule = rules[requiredRuleIndex];
+        const { isShow } = getShow();
+        if (!isShow) {
+          rule.required = false;
+        }
         if (rule.required && component) {
           if (!Reflect.has(rule, 'type')) {
             rule.type = 'string';
diff --git a/src/components/Form/src/hooks/useFormEvents.ts b/src/components/Form/src/hooks/useFormEvents.ts
index 305d91d..a4609cb 100644
--- a/src/components/Form/src/hooks/useFormEvents.ts
+++ b/src/components/Form/src/hooks/useFormEvents.ts
@@ -183,6 +183,7 @@
   async function validateFields(nameList?: NamePath[] | undefined) {
     return unref(formElRef)?.validateFields(nameList);
   }
+
   async function validate(nameList?: NamePath[] | undefined) {
     return await unref(formElRef)?.validate(nameList);
   }
diff --git a/src/views/demo/system/account/account.data.ts b/src/views/demo/system/account/account.data.ts
index e955e32..c540ccc 100644
--- a/src/views/demo/system/account/account.data.ts
+++ b/src/views/demo/system/account/account.data.ts
@@ -61,7 +61,7 @@
     label: '瀵嗙爜',
     component: 'InputPassword',
     required: true,
-    show: true,
+    show: false,
   },
   {
     label: '瑙掕壊',

--
Gitblit v1.8.0