← Blog

The Escape key skips your confirm box

A dialog with unsaved changes in it will shut on Escape without asking. There's a proper way to catch that now.

A dialog with a form in it usually wants to ask before it shuts. Are you sure, you haven't saved.

You hang that off the close button and it works. Then somebody presses Escape and the dialog shuts anyway, because the browser closes it directly and your button was never involved.

There has always been an event for that, called cancel, and you can catch Escape there. But then the question lives in two places, and two copies of the same rule drift apart eventually. Usually about a year later, when somebody else is looking at it.

The fix...

Dialogs have a requestClose() now.

dialog.requestClose();

It does what Escape does. The cancel event fires first, so your question sits in one place and both routes go through it.

close() is still there and still shuts the thing without asking, which is what you want once they've answered.

If any of it is useful on your project, say so.