diff --git a/src/app/submission/sections/form/section-form.component.spec.ts b/src/app/submission/sections/form/section-form.component.spec.ts index cd5005f852..4ea37b93e0 100644 --- a/src/app/submission/sections/form/section-form.component.spec.ts +++ b/src/app/submission/sections/form/section-form.component.spec.ts @@ -347,6 +347,22 @@ describe('SubmissionSectionFormComponent test suite', () => { } as FormFieldModel ] }, + { + fields: [ + { + selectableMetadata: [{ metadata: 'scoped.workflow.relation' }], + scope: 'WORKFLOW', + } as FormFieldModel, + ], + }, + { + fields: [ + { + selectableMetadata: [{ metadata: 'scoped.workspace.relation' }], + scope: 'WORKSPACE', + } as FormFieldModel, + ], + }, { fields: [ { @@ -375,6 +391,14 @@ describe('SubmissionSectionFormComponent test suite', () => { it('should return false for fields scoped to workflow', () => { expect((comp as any).inCurrentSubmissionScope('scoped.workflow')).toBe(false); }); + + it('should return true for relation fields scoped to workspace', () => { + expect((comp as any).inCurrentSubmissionScope('scoped.workspace.relation')).toBe(true); + }); + + it('should return false for relation fields scoped to workflow', () => { + expect((comp as any).inCurrentSubmissionScope('scoped.workflow.relation')).toBe(false); + }); }); describe('in workflow scope', () => { @@ -394,6 +418,14 @@ describe('SubmissionSectionFormComponent test suite', () => { it('should return false for fields scoped to workspace', () => { expect((comp as any).inCurrentSubmissionScope('scoped.workspace')).toBe(false); }); + + it('should return true for relation fields scoped to workflow', () => { + expect((comp as any).inCurrentSubmissionScope('scoped.workflow.relation')).toBe(true); + }); + + it('should return false for relation fields scoped to workspace', () => { + expect((comp as any).inCurrentSubmissionScope('scoped.workspace.relation')).toBe(false); + }); }); }); diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index ed7573799f..59f8ba09e5 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -38,6 +38,7 @@ import { WorkflowItem } from '../../../core/submission/models/workflowitem.model import { SubmissionObject } from '../../../core/submission/models/submission-object.model'; import { SubmissionSectionObject } from '../../objects/submission-section-object.model'; import { SubmissionSectionError } from '../../objects/submission-section-error.model'; +import { FormRowModel } from '../../../core/config/models/config-submission-form.model'; /** * This component represents a section that contains a Form. @@ -255,9 +256,15 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { * @private */ private inCurrentSubmissionScope(field: string): boolean { - const scope = this.formConfig?.rows.find(row => { - return row.fields?.[0]?.selectableMetadata?.[0]?.metadata === field; - }).fields?.[0]?.scope; + const scope = this.formConfig?.rows.find((row: FormRowModel) => { + if (row.fields?.[0]?.selectableMetadata) { + return row.fields?.[0]?.selectableMetadata?.[0]?.metadata === field; + } else if (row.fields?.[0]?.selectableRelationship) { + return row.fields?.[0]?.selectableRelationship.relationshipType === field.replace(/^relationship\./g, ''); + } else { + return false; + } + })?.fields?.[0]?.scope; switch (scope) { case SubmissionScopeType.WorkspaceItem: {