Browse Source

refactor: form-submit directive

pull/1658/head
mehmet-erim 7 years ago
parent
commit
e8b8117296
  1. 16
      npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts
  2. 2
      npm/ng-packs/packages/tenant-management/src/lib/tenant-management.module.ts

16
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 { export class FormSubmitDirective implements OnInit, OnDestroy {
@Input() @Input()
noValidateOnSubmit; notValidateOnSubmit: string | boolean;
@Input()
allowSubmit: boolean = true;
constructor( constructor(
@Self() private formGroupDirective: FormGroupDirective, @Self() private formGroupDirective: FormGroupDirective,
@ -37,19 +34,18 @@ export class FormSubmitDirective implements OnInit, OnDestroy {
fromEvent(this.host.nativeElement as HTMLElement, 'keyup') fromEvent(this.host.nativeElement as HTMLElement, 'keyup')
.pipe( .pipe(
debounceTime(200), debounceTime(200),
filter((key: KeyboardEvent) => key && key.key === 'Enter' && this.allowSubmit), filter((key: KeyboardEvent) => key && key.key === 'Enter'),
takeUntilDestroy(this), takeUntilDestroy(this),
) )
.subscribe(() => { .subscribe(() => {
this.host.nativeElement.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })); this.host.nativeElement.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
}); });
if (this.noValidateOnSubmit || typeof this.noValidateOnSubmit === 'string') {
return;
}
fromEvent(this.host.nativeElement, 'submit') fromEvent(this.host.nativeElement, 'submit')
.pipe(takeUntilDestroy(this)) .pipe(
takeUntilDestroy(this),
filter(() => !this.notValidateOnSubmit && typeof this.notValidateOnSubmit !== 'string'),
)
.subscribe(() => { .subscribe(() => {
const { form } = this.formGroupDirective; const { form } = this.formGroupDirective;

2
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 { TenantsComponent } from './components/tenants/tenants.component';
import { TenantManagementState } from './states/tenant-management.state'; import { TenantManagementState } from './states/tenant-management.state';
import { TenantManagementRoutingModule } from './tenant-management-routing.module'; import { TenantManagementRoutingModule } from './tenant-management-routing.module';
import { NgxValidateCoreModule } from '@ngx-validate/core';
@NgModule({ @NgModule({
declarations: [TenantsComponent], declarations: [TenantsComponent],
imports: [ imports: [
TenantManagementRoutingModule, TenantManagementRoutingModule,
NgxsModule.forFeature([TenantManagementState]), NgxsModule.forFeature([TenantManagementState]),
NgxValidateCoreModule,
CoreModule, CoreModule,
TableModule, TableModule,
ThemeSharedModule, ThemeSharedModule,

Loading…
Cancel
Save