Skip to content

Commit 02cfdc7

Browse files
committed
emit rasterband change on blur
1 parent 80f06a8 commit 02cfdc7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

projects/manager/src/app/rasterbands/rasterbands.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {MatDivider} from '@angular/material/list';
66
import {MatFormField, MatLabel, MatInput} from '@angular/material/input';
77
import {MatIconButton, MatButton} from '@angular/material/button';
88
import {MatIcon} from '@angular/material/icon';
9+
import {Subscription} from 'rxjs';
910

1011
interface RasterbandsForm {
1112
rasterbands: FormArray<FormGroup<RasterbandForm>>;
@@ -29,7 +30,10 @@ export class RasterbandsComponent implements OnChanges {
2930

3031
form: FormGroup<RasterbandsForm> = this.setUpForm();
3132

33+
sub?: Subscription;
34+
3235
ngOnChanges(changes: SimpleChanges): void {
36+
console.log('RasterbandsComponent.ngOnChanges', changes);
3337
if (changes.rasterbands) {
3438
this.form = this.setUpForm();
3539
}
@@ -64,7 +68,11 @@ export class RasterbandsComponent implements OnChanges {
6468
rasterbands: new FormArray<FormGroup<RasterbandForm>>(rasterbands?.map((p) => this.createRasterbandForm(p)) ?? []),
6569
});
6670

67-
form.valueChanges.subscribe(() => {
71+
if (this.sub) {
72+
this.sub.unsubscribe();
73+
}
74+
75+
this.sub = form.valueChanges.subscribe(() => {
6876
this.rasterbandsChange.emit(this.getRasterbands());
6977
});
7078

@@ -76,6 +84,7 @@ export class RasterbandsComponent implements OnChanges {
7684
name: new FormControl(p?.name ?? '', {
7785
nonNullable: true,
7886
validators: [Validators.required, geoengineValidators.notOnlyWhitespace],
87+
updateOn: 'blur',
7988
}),
8089
measurement: new FormControl(p?.measurement ?? {type: 'unitless'}, {
8190
nonNullable: true,

0 commit comments

Comments
 (0)