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