From 2d55bbf58ad134b471c666b32858dc1a714f8714 Mon Sep 17 00:00:00 2001 From: Ehsan Rezaei Date: Wed, 3 May 2023 13:03:08 +0200 Subject: [PATCH] AAE-12240: Form save button enable/disable management (#8502) * AAE-12240: Form save button enable/disable management * AAE-12240: Code improvement --- .../form/components/form-base.component.ts | 1 + .../components/form-cloud.component.spec.ts | 22 +++++++++++++++++++ .../form/components/form-cloud.component.ts | 10 ++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/core/src/lib/form/components/form-base.component.ts b/lib/core/src/lib/form/components/form-base.component.ts index c2393f4029..772d158bc2 100644 --- a/lib/core/src/lib/form/components/form-base.component.ts +++ b/lib/core/src/lib/form/components/form-base.component.ts @@ -169,6 +169,7 @@ export abstract class FormBaseComponent { if (outcome.isSystem) { if (outcome.id === FormBaseComponent.SAVE_OUTCOME_ID) { + this.disableSaveButton = true; this.saveTaskForm(); return true; } diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts index 97410dd01f..fddc165652 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts @@ -1079,6 +1079,20 @@ describe('FormCloudComponent', () => { expect(formComponent.showTitle).toBeTruthy(); }); + it('should disable save button on [save] outcome click', () => { + const formModel = new FormModel(); + const outcome = new FormOutcomeModel(formModel, { + id: FormCloudComponent.SAVE_OUTCOME_ID, + name: 'SAVE', + isSystem: true + }); + formComponent.form = formModel; + + formComponent.onOutcomeClicked(outcome); + + expect(formComponent.disableSaveButton).toBeTrue(); + }); + describe('form validations', () => { it('should be able to set visibility conditions for Attach File widget', async () => { spyOn(formCloudService, 'getForm').and.returnValue(of(conditionalUploadWidgetsMock)); @@ -1316,4 +1330,12 @@ describe('retrieve metadata on submit', () => { expect(stopPropagationSpy).toHaveBeenCalled(); }); + + it('should enable save button when form field value changed', () => { + formComponent.disableSaveButton = true; + + formService.formFieldValueChanged.next(); + + expect(formComponent.disableSaveButton).toBeFalse(); + }); }); diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts index 57119f455c..7b5da60ade 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts @@ -132,6 +132,14 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, this.form.addValuesNotPresent(valuesToSetIfNotPresent); this.onFormDataRefreshed(this.form); }); + + this.formService.formFieldValueChanged + .pipe(takeUntil(this.onDestroy$)) + .subscribe(() => { + if (this.disableSaveButton) { + this.disableSaveButton = false; + } + }); } @HostListener('keydown', ['$event']) @@ -314,7 +322,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, formValues[variable.name] = variable.value; }); - const form = new FormModel(formCloudRepresentationJSON, formValues, this.readOnly); + const form = new FormModel(formCloudRepresentationJSON, formValues, this.readOnly, this.formService); if (!form) { form.outcomes = this.getFormDefinitionOutcomes(form); }