From 70a418cfb2257e573f9792b6cc8065261c3b9bb9 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 11 Jun 2024 17:24:39 +0300 Subject: [PATCH] UI: Fixed notification template control not propagate new init value --- ...cation-template-configuration.component.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/notification/template/configuration/notification-template-configuration.component.ts b/ui-ngx/src/app/modules/home/pages/notification/template/configuration/notification-template-configuration.component.ts index eac2dc5a7e..06dd8d030e 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/template/configuration/notification-template-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/pages/notification/template/configuration/notification-template-configuration.component.ts @@ -95,9 +95,10 @@ export class NotificationTemplateConfigurationComponent implements OnDestroy, Co branding: false }; - private propagateChange = (v: any) => { }; + private propagateChange = null; private readonly destroy$ = new Subject(); private expendedBlocks: NotificationDeliveryMethod[]; + private propagateChangePending = false; constructor(private fb: FormBuilder, private translate: TranslateService) { @@ -105,7 +106,7 @@ export class NotificationTemplateConfigurationComponent implements OnDestroy, Co this.templateConfigurationForm.valueChanges.pipe( takeUntil(this.destroy$) ).subscribe((value) => { - this.propagateChange(value); + this.updateModel(value); }); } @@ -129,6 +130,12 @@ export class NotificationTemplateConfigurationComponent implements OnDestroy, Co registerOnChange(fn: any): void { this.propagateChange = fn; + if (this.propagateChangePending) { + this.propagateChangePending = false; + Promise.resolve().then(() => { + this.templateConfigurationForm.updateValueAndValidity(); + }); + } } registerOnTouched(fn: any): void { @@ -164,6 +171,14 @@ export class NotificationTemplateConfigurationComponent implements OnDestroy, Co return this.expendedBlocks.includes(name); } + private updateModel(value: Partial) { + if (this.propagateChange) { + this.propagateChange(value); + } else { + this.propagateChangePending = true; + } + } + private updateExpandedForm() { this.expendedBlocks = []; Object.keys(this.templateConfigurationForm.controls).forEach((name: NotificationDeliveryMethod) => {