From 617632b358194bcc6da51f3c799727a00ac44d7a Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Thu, 12 Apr 2018 01:44:09 +0100 Subject: [PATCH] mgr/dashboard: Force focus on submit Forcing focus on submit button will guarantee that all inputs will lose focus before submission. Signed-off-by: Ricardo Marques --- .../components/submit-button/submit-button.component.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/submit-button/submit-button.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/submit-button/submit-button.component.ts index c9b0ac41645..3cc35df4d7b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/submit-button/submit-button.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/submit-button/submit-button.component.ts @@ -45,6 +45,8 @@ export class SubmitButtonComponent implements OnInit { } submit() { + this.focusButton(); + if (this.form.invalid) { this.focusInvalid(); return; @@ -54,6 +56,12 @@ export class SubmitButtonComponent implements OnInit { this.submitAction.emit(); } + focusButton() { + this.elRef.nativeElement.offsetParent.querySelector( + 'button[type="submit"]' + ).focus(); + } + focusInvalid() { const target = this.elRef.nativeElement.offsetParent.querySelector( 'input.ng-invalid, select.ng-invalid' -- 2.39.5