From d3d322d444242ad43c1ac9f7313433cb23f7a87c Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 18 Nov 2021 02:01:09 +0200 Subject: [PATCH] fix form value not changed when inputs change --- .../editable-input/editable-input.component.html | 2 +- .../inputs/editable-input/editable-input.component.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/inputs/editable-input/editable-input.component.html b/src/lib/inputs/editable-input/editable-input.component.html index 5d731a5..5d369b8 100644 --- a/src/lib/inputs/editable-input/editable-input.component.html +++ b/src/lib/inputs/editable-input/editable-input.component.html @@ -15,7 +15,7 @@
- +
diff --git a/src/lib/inputs/editable-input/editable-input.component.ts b/src/lib/inputs/editable-input/editable-input.component.ts index 2936c44..f544d0e 100644 --- a/src/lib/inputs/editable-input/editable-input.component.ts +++ b/src/lib/inputs/editable-input/editable-input.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, EventEmitter, HostBinding, Input, Output } from '@angular/core'; +import { ChangeDetectionStrategy, Component, EventEmitter, HostBinding, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; import { Required } from '../../utils'; import { CircleButtonType } from '../../buttons'; @@ -8,7 +8,7 @@ import { CircleButtonType } from '../../buttons'; styleUrls: ['./editable-input.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class EditableInputComponent { +export class EditableInputComponent implements OnChanges { @Input() @Required() value!: string; @Input() editTooltip?: string; @Input() saveTooltip?: string; @@ -32,6 +32,12 @@ export class EditableInputComponent { this.newValue = this.value; } + ngOnChanges(changes: SimpleChanges): void { + if (changes.value) { + this.editing = false; + } + } + saveValue(): void { this.save.emit(this.newValue); this.editing = false;