Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/shared/form/builder/form-builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,9 @@ export class FormBuilderService extends DynamicFormService {
return this.getDefaultTypeBindModelId();
}

/** Type-bind controlling fields (underscore notation, e.g. `dc_type`, `edm_type`) from `submit.type-bind.field`. */
getTypeFieldValues(): string[] {
return Array.from(this.typeFields.values());
}

}
1 change: 1 addition & 0 deletions src/app/shared/mocks/form-builder-service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function getMockFormBuilderService(): FormBuilderService {
),
getTypeBindModelUpdates: EMPTY,
resolveTypeBindModelId: undefined,
getTypeFieldValues: ['dc_type'],
});

// as the real implementation behaves for a reference the type field map does not remap
Expand Down
30 changes: 30 additions & 0 deletions src/app/submission/sections/form/section-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,36 @@ describe('SubmissionSectionFormComponent test suite', () => {

});

it('should call dispatchSaveSection on form change when a type-bind field (e.g. dc.type) changes', () => {
spyOn(comp, 'hasStoredValue').and.returnValue(false);
formOperationsService.getFieldPathSegmentedFromChangeEvent.and.returnValue('dc.type');
formOperationsService.getFieldValueFromChangeEvent.and.returnValue({ value: 'Corpus' });

comp.onChange(dynamicFormControlEvent);

expect(submissionServiceStub.dispatchSaveSection).toHaveBeenCalledWith(submissionId, sectionObject.id);
});

it('should call dispatchSaveSection on form change when a sponsor value changes', () => {
spyOn(comp, 'hasStoredValue').and.returnValue(false);
formOperationsService.getFieldPathSegmentedFromChangeEvent.and.returnValue('local.sponsor');
formOperationsService.getFieldValueFromChangeEvent.and.returnValue({ value: 'EU' });

comp.onChange(dynamicFormControlEvent);

expect(submissionServiceStub.dispatchSaveSection).toHaveBeenCalledWith(submissionId, sectionObject.id);
});

it('should not call dispatchSaveSection on form change for a regular field', () => {
spyOn(comp, 'hasStoredValue').and.returnValue(false);
formOperationsService.getFieldPathSegmentedFromChangeEvent.and.returnValue('dc.description');
formOperationsService.getFieldValueFromChangeEvent.and.returnValue('some text');

comp.onChange(dynamicFormControlEvent);

expect(submissionServiceStub.dispatchSaveSection).not.toHaveBeenCalled();
});

it('should set previousValue on form focus event', () => {
formBuilderService.hasMappedGroupValue.and.returnValue(false);
formOperationsService.getFieldValueFromChangeEvent.and.returnValue('test');
Expand Down
9 changes: 9 additions & 0 deletions src/app/submission/sections/form/section-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
isNotEmpty,
isUndefined,
} from '../../../shared/empty.util';
import { AUTHOR_METADATA_FIELD_NAME } from '../../../shared/form/builder/ds-dynamic-form-ui/models/clarin-name.model';
import { SPONSOR_METADATA_NAME } from '../../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-complex.model';
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
import { FormFieldPreviousValueObject } from '../../../shared/form/builder/models/form-field-previous-value-object';
import { FormComponent } from '../../../shared/form/form.component';
Expand Down Expand Up @@ -446,6 +448,13 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
if ((environment.submission.autosave.metadata.indexOf(metadata) !== -1 && isNotEmpty(value)) || this.hasRelatedCustomError(metadata)) {
this.submissionService.dispatchSave(this.submissionId);
}

// Save immediately when a type-bind field (values like `dc_type`, `edm_type`) or a sponsor/author value changes.
const isTypeBindField = this.formBuilderService.getTypeFieldValues()
.some((typeValue) => typeValue === metadata.replace(/\./g, '_'));
if (isTypeBindField || [SPONSOR_METADATA_NAME, AUTHOR_METADATA_FIELD_NAME].includes(metadata)) {
this.submissionService.dispatchSaveSection(this.submissionId, this.sectionData.id);
}
}

private hasRelatedCustomError(medatata): boolean {
Expand Down
Loading