diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index 4b657fe8bb..b9979bde06 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -22,6 +22,7 @@ import { EllipsisDirective } from './directives/ellipsis.directive'; import { AutofocusDirective } from './directives/autofocus.directive'; import { InputEventDebounceDirective } from './directives/debounce.directive'; import { ClickEventStopPropagationDirective } from './directives/stop-propagation.directive'; +import { FormKeyupListenerDirective } from './directives/form-keyup-listener.directive'; @NgModule({ imports: [ @@ -39,6 +40,7 @@ import { ClickEventStopPropagationDirective } from './directives/stop-propagatio DynamicLayoutComponent, AutofocusDirective, EllipsisDirective, + FormKeyupListenerDirective, LocalizationPipe, PermissionDirective, VisibilityDirective, @@ -55,6 +57,7 @@ import { ClickEventStopPropagationDirective } from './directives/stop-propagatio DynamicLayoutComponent, AutofocusDirective, EllipsisDirective, + FormKeyupListenerDirective, LocalizationPipe, PermissionDirective, VisibilityDirective, diff --git a/npm/ng-packs/packages/core/src/lib/directives/form-keyup-listener.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/form-keyup-listener.directive.ts new file mode 100644 index 0000000000..2c9b5d3410 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/directives/form-keyup-listener.directive.ts @@ -0,0 +1,23 @@ +import { Directive, ElementRef, EventEmitter, Output, OnDestroy } from '@angular/core'; +import { fromEvent } from 'rxjs'; +import { debounceTime, filter, tap } from 'rxjs/operators'; +import { takeUntilDestroy } from '../utils/rxjs-utils'; + +@Directive({ + selector: 'form[ngSubmit]', +}) +export class FormKeyupListenerDirective implements OnDestroy { + @Output() ngSubmit = new EventEmitter(); + + constructor(private elRef: ElementRef) { + fromEvent(elRef.nativeElement as HTMLElement, 'keyup') + .pipe( + debounceTime(200), + filter((key: KeyboardEvent) => key && key.key === 'Enter'), + takeUntilDestroy(this), + ) + .subscribe(() => this.ngSubmit.emit()); + } + + ngOnDestroy(): void {} +} diff --git a/npm/ng-packs/packages/core/src/lib/directives/index.ts b/npm/ng-packs/packages/core/src/lib/directives/index.ts index de5846382c..d3da66bed4 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/index.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/index.ts @@ -1,4 +1,5 @@ export * from './autofocus.directive'; export * from './ellipsis.directive'; +export * from './form-keyup-listener.directive'; export * from './permission.directive'; export * from './visibility.directive'; diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.html b/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.html index 3a122357c7..b0624e9d82 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.html +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.html @@ -3,7 +3,7 @@

{{ 'AbpIdentity::PersonalInfo' | abpLocalization }}

-
+
* @@ -36,6 +36,6 @@ - {{ 'AbpIdentity::Save' | abpLocalization }} + {{ 'AbpIdentity::Save' | abpLocalization }} diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.ts index f2e4683239..0dc8ef2768 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/profile/profile.component.ts @@ -54,7 +54,7 @@ export class ProfileComponent implements OnChanges { }); } - onSubmit() { + submit() { if (this.form.invalid) return; this.modalBusy = true;