diff --git a/packages/core/src/__tests__/field.spec.ts b/packages/core/src/__tests__/field.spec.ts index 9ff265b4e14..689c4b23d28 100644 --- a/packages/core/src/__tests__/field.spec.ts +++ b/packages/core/src/__tests__/field.spec.ts @@ -1143,3 +1143,83 @@ test('nested fields hidden and validate', async () => { await form.validate() expect(form.invalid).toBeFalsy() }) + +test('deep nested fields hidden and validate', async () => { + const form = attach(createForm()) + const parent1 = attach( + form.createVoidField({ + name: 'parent1', + }) + ) + const parent2 = attach( + form.createVoidField({ + name: 'parent2', + basePath: 'parent1', + }) + ) + const aa = attach( + form.createField({ + name: 'aa', + basePath: 'parent1.parent2', + required: true, + }) + ) + const bb = attach( + form.createField({ + name: 'bb', + basePath: 'parent1.parent2', + required: true, + }) + ) + try { + await form.validate() + } catch {} + expect(form.invalid).toBeTruthy() + parent2.display = 'visible' + parent1.display = 'hidden' + expect(parent2.display).toEqual('hidden') + expect(aa.display).toEqual('hidden') + expect(bb.display).toEqual('hidden') + await form.validate() + expect(form.invalid).toBeFalsy() +}) + +test('deep nested fields hidden and validate with middle hidden', async () => { + const form = attach(createForm()) + const parent1 = attach( + form.createVoidField({ + name: 'parent1', + }) + ) + const parent2 = attach( + form.createVoidField({ + name: 'parent2', + basePath: 'parent1', + }) + ) + const aa = attach( + form.createField({ + name: 'aa', + basePath: 'parent1.parent2', + required: true, + }) + ) + const bb = attach( + form.createField({ + name: 'bb', + basePath: 'parent1.parent2', + required: true, + }) + ) + try { + await form.validate() + } catch {} + expect(form.invalid).toBeTruthy() + parent2.display = 'hidden' + parent1.display = 'none' + expect(parent2.display).toEqual('hidden') + expect(aa.display).toEqual('hidden') + expect(bb.display).toEqual('hidden') + await form.validate() + expect(form.invalid).toBeFalsy() +}) diff --git a/packages/core/src/models/Field.ts b/packages/core/src/models/Field.ts index 9b86afc3a42..7690cde84cf 100644 --- a/packages/core/src/models/Field.ts +++ b/packages/core/src/models/Field.ts @@ -351,6 +351,11 @@ export class Field< get display(): FieldDisplayTypes { const parentDisplay = this.parent?.display + if (parentDisplay && parentDisplay !== 'visible') { + if (this.selfDisplay && this.selfDisplay !== 'visible') + return this.selfDisplay + return parentDisplay + } if (this.selfDisplay) return this.selfDisplay return parentDisplay || this.form.display || 'visible' } diff --git a/packages/core/src/models/VoidField.ts b/packages/core/src/models/VoidField.ts index fcc2984b568..b017e681264 100644 --- a/packages/core/src/models/VoidField.ts +++ b/packages/core/src/models/VoidField.ts @@ -175,6 +175,11 @@ export class VoidField { get display(): FieldDisplayTypes { const parentDisplay = this.parent?.display + if (parentDisplay && parentDisplay !== 'visible') { + if (this.selfDisplay && this.selfDisplay !== 'visible') + return this.selfDisplay + return parentDisplay + } if (isValid(this.selfDisplay)) return this.selfDisplay return parentDisplay || this.form.display || 'visible' } diff --git a/packages/core/src/shared/internals.ts b/packages/core/src/shared/internals.ts index ddcfea6d3d4..1a13052feee 100644 --- a/packages/core/src/shared/internals.ts +++ b/packages/core/src/shared/internals.ts @@ -197,11 +197,7 @@ export const validateToFeedbacks = async ( }) const takeSkipCondition = () => { if (field.display !== 'visible') return true - if (field.parent?.display) { - if (field.parent.display !== 'visible') return true - } if (field.pattern !== 'editable') return true - return false }