Skip to content

Commit 43a45b7

Browse files
committed
fix(form): ensure that the Form component does not verify hidden form items
1 parent e0dc5cf commit 43a45b7

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

CHANGELOG.zh_CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- `BasicTree` 新增`clickRowToExpand`,用于单击树节点展开
66
- 新增 SvgIcon 插件及示例
7+
- 账号管理界面增加左侧部门树
78

89
### ⚡ Performance Improvements
910

@@ -22,6 +23,7 @@
2223
- 修复账号管理新增未清空旧数据
2324
- form 组件应允许 setFieldsValue 方法值为 null 或者 undefined
2425
- 确保单级面包屑正确跳转
26+
- 确保 Form 组件不校验隐藏的表单项
2527

2628
## 2.0.2 (2021-03-04)
2729

src/components/Form/src/components/FormItem.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default defineComponent({
9797
return disabled;
9898
});
9999

100-
function getShow() {
100+
function getShow(): { isShow: boolean; isIfShow: boolean } {
101101
const { show, ifShow } = props.schema;
102102
const { showAdvancedButton } = props.formProps;
103103
const itemIsAdvanced = showAdvancedButton
@@ -151,6 +151,10 @@ export default defineComponent({
151151
const { rulesMessageJoinLabel: globalRulesMessageJoinLabel } = props.formProps;
152152
if (requiredRuleIndex !== -1) {
153153
const rule = rules[requiredRuleIndex];
154+
const { isShow } = getShow();
155+
if (!isShow) {
156+
rule.required = false;
157+
}
154158
if (rule.required && component) {
155159
if (!Reflect.has(rule, 'type')) {
156160
rule.type = 'string';

src/components/Form/src/hooks/useFormEvents.ts

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export function useFormEvents({
183183
async function validateFields(nameList?: NamePath[] | undefined) {
184184
return unref(formElRef)?.validateFields(nameList);
185185
}
186+
186187
async function validate(nameList?: NamePath[] | undefined) {
187188
return await unref(formElRef)?.validate(nameList);
188189
}

src/views/demo/system/account/account.data.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [
6161
label: '密码',
6262
component: 'InputPassword',
6363
required: true,
64-
show: true,
64+
show: false,
6565
},
6666
{
6767
label: '角色',

0 commit comments

Comments
 (0)