refactor: form-submit directive

pull/1658/head
mehmet-erim 6 years ago
parent d05ad8cc10
commit e8b8117296

@ -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;

@ -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,

Loading…
Cancel
Save