check also form value changes when using autocomplete
This commit is contained in:
parent
223080763f
commit
9124c1f284
@ -4,7 +4,7 @@ import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
|||||||
import { hasFormChanged, IqserEventTarget } from '../utils';
|
import { hasFormChanged, IqserEventTarget } from '../utils';
|
||||||
import { ConfirmOptions } from '.';
|
import { ConfirmOptions } from '.';
|
||||||
import { ConfirmationDialogService } from './confirmation-dialog.service';
|
import { ConfirmationDialogService } from './confirmation-dialog.service';
|
||||||
import { debounceTime, firstValueFrom, from, fromEvent, mergeMap, Subscription } from 'rxjs';
|
import { debounceTime, firstValueFrom, fromEvent, merge, Subscription } from 'rxjs';
|
||||||
import { LoadingService } from '../loading';
|
import { LoadingService } from '../loading';
|
||||||
import { Toaster } from '../services';
|
import { Toaster } from '../services';
|
||||||
import { IconButtonTypes } from '../buttons';
|
import { IconButtonTypes } from '../buttons';
|
||||||
@ -32,23 +32,6 @@ export abstract class BaseDialogComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
protected constructor(protected readonly _dialogRef: MatDialogRef<BaseDialogComponent>, private readonly _isInEditMode?: boolean) {}
|
protected constructor(protected readonly _dialogRef: MatDialogRef<BaseDialogComponent>, private readonly _isInEditMode?: boolean) {}
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
this.#subscriptions.add(
|
|
||||||
this._dialogRef.backdropClick().subscribe(() => {
|
|
||||||
this.close();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
this.#subscriptions.add(
|
|
||||||
from(['keyup', 'input'])
|
|
||||||
.pipe(
|
|
||||||
mergeMap(event => fromEvent(window, event)),
|
|
||||||
debounceTime(0),
|
|
||||||
tap(() => (this.#hasErrors = !!document.getElementsByClassName('ng-invalid')[0])),
|
|
||||||
)
|
|
||||||
.subscribe(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get valid(): boolean {
|
get valid(): boolean {
|
||||||
return !this.form || this.form.valid;
|
return !this.form || this.form.valid;
|
||||||
}
|
}
|
||||||
@ -61,6 +44,17 @@ export abstract class BaseDialogComponent implements OnInit, OnDestroy {
|
|||||||
return !this.valid || !this.changed || this.#hasErrors;
|
return !this.valid || !this.changed || this.#hasErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.#subscriptions.add(this._dialogRef.backdropClick().subscribe(() => this.close()));
|
||||||
|
|
||||||
|
const events = [fromEvent(window, 'keyup'), fromEvent(window, 'input'), this.form?.valueChanges];
|
||||||
|
const events$ = merge(...events).pipe(
|
||||||
|
debounceTime(10),
|
||||||
|
tap(() => (this.#hasErrors = !!document.getElementsByClassName('ng-invalid')[0])),
|
||||||
|
);
|
||||||
|
this.#subscriptions.add(events$.subscribe());
|
||||||
|
}
|
||||||
|
|
||||||
abstract save(options?: SaveOptions): void;
|
abstract save(options?: SaveOptions): void;
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user