From 5817c45e0173beee4cc886d4180d32ddae0350e6 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Mon, 8 Jul 2019 11:34:14 +0200 Subject: [PATCH] Hotfix clearing of extensions on navigation --- .../extension-field.component.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/client/src/app/shared/components/extension-field/extension-field.component.ts b/client/src/app/shared/components/extension-field/extension-field.component.ts index 5dc5231c0..e96794448 100644 --- a/client/src/app/shared/components/extension-field/extension-field.component.ts +++ b/client/src/app/shared/components/extension-field/extension-field.component.ts @@ -1,13 +1,14 @@ -import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; -import { BehaviorSubject } from 'rxjs'; +import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core'; +import { BehaviorSubject, Subscription } from 'rxjs'; import { FormGroup, FormBuilder } from '@angular/forms'; +import { Router, NavigationEnd } from '@angular/router'; @Component({ selector: 'os-extension-field', templateUrl: './extension-field.component.html', styleUrls: ['./extension-field.component.scss'] }) -export class ExtensionFieldComponent implements OnInit { +export class ExtensionFieldComponent implements OnInit, OnDestroy { /** * Optional additional classes for the `mat-chip`. */ @@ -113,18 +114,31 @@ export class ExtensionFieldComponent implements OnInit { */ public editMode = false; + /** + * Hold the nav subscription + */ + private navigationSubscription: Subscription; + /** * Constructor * * @param fb The FormBuilder */ - public constructor(private fb: FormBuilder) {} + public constructor(private fb: FormBuilder, private router: Router) {} /** * OnInit-method. */ public ngOnInit(): void { + this.navigationSubscription = this.router.events.subscribe(navEvent => { + if (navEvent instanceof NavigationEnd) { + this.editMode = false; + this.extensionFieldForm.reset(); + } + }); + this.initInput(); + this.extensionFieldForm = this.fb.group({ list: this.searchList ? [[]] : undefined }); @@ -133,7 +147,7 @@ export class ExtensionFieldComponent implements OnInit { if (this.listSubmitOnChange) { this.listChange.emit(value); } - if (this.appendValueToInput) { + if (this.appendValueToInput && this.inputControl.length) { this.inputControl = this.inputControl.concat( `[${this.listValuePrefix}${value}${this.listValueSuffix}]` ); @@ -141,6 +155,13 @@ export class ExtensionFieldComponent implements OnInit { }); } + /** + * On destroy unsubscribe from the nav subscription + */ + public ngOnDestroy(): void { + this.navigationSubscription.unsubscribe(); + } + /** * Function to switch to or from editing-mode. *