fix form value not changed when inputs change

This commit is contained in:
Dan Percic 2021-11-18 02:01:09 +02:00
parent 8131705558
commit d3d322d444
2 changed files with 9 additions and 3 deletions

View File

@ -15,7 +15,7 @@
<ng-container *ngIf="editing">
<form (submit)="saveValue()">
<div [class]="'iqser-input-group ' + class">
<input [(ngModel)]="newValue" [placeholder]="placeholder" name="name" />
<input (ngModelChange)="newValue = $event" [ngModel]="value" [placeholder]="placeholder" name="name" />
</div>
</form>

View File

@ -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;