How to close dialog with Enter key

UI Components for Angular
Post Reply
al_ex
Posts: 1
Joined: 15 Feb 2018, 18:19

15 Feb 2018, 18:40

Hi

I need to displaying a <p-dialog> that contains two <p-dropdown> boxes. The user can enter a number in one of those boxes, then hit the Enter key to close the dialog and apply this value. Beside this he can hit anytime the Escape key to close the dialog without applying the changes (pretty intuitive). Is this somehow possible (may be without any 'Apply'and 'Close' buttons in the dialog)?

Btw.: What is the intent of the event parameter in onHide(). I tried to pass the $event into my onHide() method, but the object is always empty. No matter how I close the dialog (ESC / toggle visible property).

User avatar
Ctrl-C
Posts: 97
Joined: 29 Sep 2016, 04:21

15 Feb 2018, 22:05

Put these fields inside a form within the dialog and close when form is submitted or value changed.

mpscheidt
Posts: 3
Joined: 03 Dec 2018, 10:23

01 Jul 2019, 16:24

Use a host listener to listen for keyboard events.

Code: Select all

@HostListener("window:keyup", ["$event"])
keyEvent(event: KeyboardEvent) {
    console.log(event);

    // ESC key
    if (event.keyCode === 27) {
      // your logic;
    }
}

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 10 guests