Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Fix bug #1243 (Input fields don't work in dialogs) #1722

Merged
merged 1 commit into from
Sep 27, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/widgets/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ define(function (require, exports, module) {
buttonId = null,
which = String.fromCharCode(e.which);

if (e.which === KeyEvent.DOM_VK_RETURN) {
// There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
var inFormField = ($(e.target).filter(":input").length > 0),
inTextArea = (e.target.tagName === "TEXTAREA");

if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to allow enter keys to create new lines.

// Click primary button
if (primaryBtn) {
buttonId = primaryBtn.attr("data-button-id");
Expand All @@ -87,7 +91,7 @@ define(function (require, exports, module) {
}
} else { // if (brackets.platform === "win") {
// 'N' Don't Save
if (which === "N") {
if (which === "N" && !inFormField) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inFormField is assigned based on ":input" filter.

":input" not only filters the actual text fields, but also includes other types of input. So if the focus is on a button in the dialog, inFormField will be true and this if condition will return false. Then we won't be processing "N" key for the corresponding button.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bootstrap uses <a> for dialog buttons instead of <button>, so currently this isn't a problem. Do you still think we should change it? I suppose we could filter only on tagName (allow <input> and <textarea> and maybe <select>, but nothing else?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay to keep it as is since our special handling of "N" key has nothing to do with mnemonics in the dialog anyway. When we make a big change to support the mnemonics in the dialog in the future, then we can limit it to the actual text field elements only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good -- thanks!

if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
buttonId = DIALOG_BTN_DONTSAVE;
}
Expand All @@ -96,8 +100,7 @@ define(function (require, exports, module) {

if (buttonId) {
_dismissDialog(this, buttonId);
} else if (!($.contains(this.get(0), e.target)) ||
($(e.target).filter(":input").length === 0)) {
} else if (!($.contains(this.get(0), e.target)) || !inFormField) {
// Stop the event if the target is not inside the dialog
// or if the target is not a form element.
// TODO (issue #414): more robust handling of dialog scoped
Expand Down