|
|
@ -7,7 +7,7 @@ import { |
|
|
OnDestroy, |
|
|
OnDestroy, |
|
|
OnInit, |
|
|
OnInit, |
|
|
Output, |
|
|
Output, |
|
|
Self |
|
|
Self, |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { FormControl, FormGroup, FormGroupDirective } from '@angular/forms'; |
|
|
import { FormControl, FormGroup, FormGroupDirective } from '@angular/forms'; |
|
|
import { fromEvent } from 'rxjs'; |
|
|
import { fromEvent } from 'rxjs'; |
|
|
@ -18,7 +18,7 @@ type Controls = { [key: string]: FormControl } | FormGroup[]; |
|
|
|
|
|
|
|
|
@Directive({ |
|
|
@Directive({ |
|
|
// tslint:disable-next-line: directive-selector
|
|
|
// tslint:disable-next-line: directive-selector
|
|
|
selector: 'form[ngSubmit][formGroup]' |
|
|
selector: 'form[ngSubmit][formGroup]', |
|
|
}) |
|
|
}) |
|
|
export class FormSubmitDirective implements OnInit, OnDestroy { |
|
|
export class FormSubmitDirective implements OnInit, OnDestroy { |
|
|
@Input() |
|
|
@Input() |
|
|
@ -31,7 +31,7 @@ export class FormSubmitDirective implements OnInit, OnDestroy { |
|
|
constructor( |
|
|
constructor( |
|
|
@Self() private formGroupDirective: FormGroupDirective, |
|
|
@Self() private formGroupDirective: FormGroupDirective, |
|
|
private host: ElementRef<HTMLFormElement>, |
|
|
private host: ElementRef<HTMLFormElement>, |
|
|
private cdRef: ChangeDetectorRef |
|
|
private cdRef: ChangeDetectorRef, |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
ngOnInit() { |
|
|
@ -44,7 +44,7 @@ export class FormSubmitDirective implements OnInit, OnDestroy { |
|
|
.pipe( |
|
|
.pipe( |
|
|
debounceTime(200), |
|
|
debounceTime(200), |
|
|
filter((key: KeyboardEvent) => key && key.key === 'Enter'), |
|
|
filter((key: KeyboardEvent) => key && key.key === 'Enter'), |
|
|
takeUntilDestroy(this) |
|
|
takeUntilDestroy(this), |
|
|
) |
|
|
) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
if (!this.executedNgSubmit) { |
|
|
if (!this.executedNgSubmit) { |
|
|
@ -53,17 +53,6 @@ export class FormSubmitDirective implements OnInit, OnDestroy { |
|
|
|
|
|
|
|
|
this.executedNgSubmit = false; |
|
|
this.executedNgSubmit = false; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
fromEvent(this.host.nativeElement, 'submit') |
|
|
|
|
|
.pipe( |
|
|
|
|
|
takeUntilDestroy(this), |
|
|
|
|
|
filter(() => !this.notValidateOnSubmit && typeof this.notValidateOnSubmit !== 'string') |
|
|
|
|
|
) |
|
|
|
|
|
.subscribe(() => { |
|
|
|
|
|
if (!this.executedNgSubmit) { |
|
|
|
|
|
this.markAsDirty(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnDestroy(): void {} |
|
|
ngOnDestroy(): void {} |
|
|
|