From e8b8117296b6f3e63614bed3ce54f01e19f3a9ca Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 19 Aug 2019 11:06:49 +0300 Subject: [PATCH] refactor: form-submit directive --- .../src/lib/directives/form-submit.directive.ts | 16 ++++++---------- .../src/lib/tenant-management.module.ts | 2 ++ 2 files changed, 8 insertions(+), 10 deletions(-) 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 1672e6099a..a3ea93a753 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 @@ -22,10 +22,7 @@ type Controls = { [key: string]: FormControl } | FormGroup[]; }) export class FormSubmitDirective implements OnInit, OnDestroy { @Input() - noValidateOnSubmit; - - @Input() - allowSubmit: boolean = true; + notValidateOnSubmit: string | boolean; constructor( @Self() private formGroupDirective: FormGroupDirective, @@ -37,19 +34,18 @@ export class FormSubmitDirective implements OnInit, OnDestroy { fromEvent(this.host.nativeElement as HTMLElement, 'keyup') .pipe( debounceTime(200), - filter((key: KeyboardEvent) => key && key.key === 'Enter' && this.allowSubmit), + filter((key: KeyboardEvent) => key && key.key === 'Enter'), takeUntilDestroy(this), ) .subscribe(() => { this.host.nativeElement.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })); }); - if (this.noValidateOnSubmit || typeof this.noValidateOnSubmit === 'string') { - return; - } - fromEvent(this.host.nativeElement, 'submit') - .pipe(takeUntilDestroy(this)) + .pipe( + takeUntilDestroy(this), + filter(() => !this.notValidateOnSubmit && typeof this.notValidateOnSubmit !== 'string'), + ) .subscribe(() => { const { form } = this.formGroupDirective; diff --git a/npm/ng-packs/packages/tenant-management/src/lib/tenant-management.module.ts b/npm/ng-packs/packages/tenant-management/src/lib/tenant-management.module.ts index 2850111dcc..fd1e0e72e9 100644 --- a/npm/ng-packs/packages/tenant-management/src/lib/tenant-management.module.ts +++ b/npm/ng-packs/packages/tenant-management/src/lib/tenant-management.module.ts @@ -7,12 +7,14 @@ import { TableModule } from 'primeng/table'; import { TenantsComponent } from './components/tenants/tenants.component'; import { TenantManagementState } from './states/tenant-management.state'; import { TenantManagementRoutingModule } from './tenant-management-routing.module'; +import { NgxValidateCoreModule } from '@ngx-validate/core'; @NgModule({ declarations: [TenantsComponent], imports: [ TenantManagementRoutingModule, NgxsModule.forFeature([TenantManagementState]), + NgxValidateCoreModule, CoreModule, TableModule, ThemeSharedModule,