diff --git a/npm/ng-packs/packages/account/src/lib/services/account.service.ts b/npm/ng-packs/packages/account/src/lib/services/account.service.ts index 6a660a695d..dc7693b693 100644 --- a/npm/ng-packs/packages/account/src/lib/services/account.service.ts +++ b/npm/ng-packs/packages/account/src/lib/services/account.service.ts @@ -25,6 +25,6 @@ export class AccountService { body, }; - return this.rest.request(request, { throwErr: true }); + return this.rest.request(request, { skipHandleError: true }); } } diff --git a/npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts index a3ea93a753..c77016ce7f 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts @@ -1,19 +1,18 @@ import { + ChangeDetectorRef, Directive, ElementRef, + EventEmitter, + Input, OnDestroy, OnInit, - Self, - ChangeDetectorRef, - HostBinding, - Input, Output, - EventEmitter, + Self, } from '@angular/core'; -import { FormGroupDirective, FormGroup, FormControl, ɵNgNoValidate } from '@angular/forms'; +import { FormControl, FormGroup, FormGroupDirective } from '@angular/forms'; import { fromEvent } from 'rxjs'; -import { takeUntilDestroy } from '../utils'; import { debounceTime, filter } from 'rxjs/operators'; +import { takeUntilDestroy } from '../utils'; type Controls = { [key: string]: FormControl } | FormGroup[]; @@ -24,6 +23,11 @@ export class FormSubmitDirective implements OnInit, OnDestroy { @Input() notValidateOnSubmit: string | boolean; + @Output() + ngSubmit = new EventEmitter(); + + executedNgSubmit: boolean = false; + constructor( @Self() private formGroupDirective: FormGroupDirective, private host: ElementRef, @@ -31,6 +35,11 @@ export class FormSubmitDirective implements OnInit, OnDestroy { ) {} ngOnInit() { + this.formGroupDirective.ngSubmit.pipe(takeUntilDestroy(this)).subscribe(() => { + this.markAsDirty(); + this.executedNgSubmit = true; + }); + fromEvent(this.host.nativeElement as HTMLElement, 'keyup') .pipe( debounceTime(200), @@ -38,7 +47,11 @@ export class FormSubmitDirective implements OnInit, OnDestroy { takeUntilDestroy(this), ) .subscribe(() => { - this.host.nativeElement.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })); + if (!this.executedNgSubmit) { + this.host.nativeElement.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })); + } + + this.executedNgSubmit = false; }); fromEvent(this.host.nativeElement, 'submit') @@ -47,16 +60,22 @@ export class FormSubmitDirective implements OnInit, OnDestroy { filter(() => !this.notValidateOnSubmit && typeof this.notValidateOnSubmit !== 'string'), ) .subscribe(() => { - const { form } = this.formGroupDirective; - - setDirty(form.controls as { [key: string]: FormControl }); - form.markAsDirty(); - - this.cdRef.detectChanges(); + if (!this.executedNgSubmit) { + this.markAsDirty(); + } }); } ngOnDestroy(): void {} + + markAsDirty() { + const { form } = this.formGroupDirective; + + setDirty(form.controls as { [key: string]: FormControl }); + form.markAsDirty(); + + this.cdRef.detectChanges(); + } } function setDirty(controls: Controls) { diff --git a/npm/ng-packs/packages/core/src/lib/models/rest.ts b/npm/ng-packs/packages/core/src/lib/models/rest.ts index 81e035f0d4..a494bbbc63 100644 --- a/npm/ng-packs/packages/core/src/lib/models/rest.ts +++ b/npm/ng-packs/packages/core/src/lib/models/rest.ts @@ -2,7 +2,7 @@ import { HttpHeaders, HttpParams } from '@angular/common/http'; export namespace Rest { export interface Config { - throwErr?: boolean; + skipHandleError?: boolean; observe?: Observe; } diff --git a/npm/ng-packs/packages/core/src/lib/services/profile.service.ts b/npm/ng-packs/packages/core/src/lib/services/profile.service.ts index 48065619ff..38d5fb3a7b 100644 --- a/npm/ng-packs/packages/core/src/lib/services/profile.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/profile.service.ts @@ -28,13 +28,13 @@ export class ProfileService { return this.rest.request(request); } - changePassword(body: Profile.ChangePasswordRequest, throwErr: boolean = false): Observable { + changePassword(body: Profile.ChangePasswordRequest, skipHandleError: boolean = false): Observable { const request: Rest.Request = { method: 'POST', url: '/api/identity/my-profile/change-password', body, }; - return this.rest.request(request, { throwErr }); + return this.rest.request(request, { skipHandleError }); } } diff --git a/npm/ng-packs/packages/core/src/lib/services/rest.service.ts b/npm/ng-packs/packages/core/src/lib/services/rest.service.ts index 4d003e2daf..7ff1a42af0 100644 --- a/npm/ng-packs/packages/core/src/lib/services/rest.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/rest.service.ts @@ -16,17 +16,17 @@ export class RestService { handleError(err: any): Observable { this.store.dispatch(new RestOccurError(err)); console.error(err); - return NEVER; + return throwError(err); } request(request: HttpRequest | Rest.Request, config: Rest.Config = {}, api?: string): Observable { - const { observe = Rest.Observe.Body, throwErr } = config; + const { observe = Rest.Observe.Body, skipHandleError } = config; const url = api || this.store.selectSnapshot(ConfigState.getApiUrl()) + request.url; const { method, ...options } = request; return this.http.request(method, url, { observe, ...options } as any).pipe( observe === Rest.Observe.Body ? take(1) : null, catchError(err => { - if (throwErr) { + if (skipHandleError) { return throwError(err); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts index 6c3b9254c4..917e981338 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts @@ -27,7 +27,13 @@ import { Toaster } from '../../models/toaster'; -