This may very well be a "won't fix", but I thought it was worth documenting. The following tests were done with Firefox (I haven't tried with other browsers):

In Drupal 6, pressing the "enter" key in one of the input fields on the node submission page either
(a) submits the node, or
(b) does nothing
(On some forms it does "a", on some forms it does "b"... I can't figure out exactly what controls the behavior.)

In Drupal 5, the behavior was a bit different:
(a) previews the node, or
(b) does nothing

It looks like the change between Drupal 5 and 6 is due to http://drupal.org/node/195678 which puts the "save" button out in front on submission forms.

The behavior in Drupal 6 is not great, in my opinion -- people have a tendency to hit "enter" by mistake, and submitting the node (rather than previewing it) seems like it will lead to a lot of half-finished nodes being submitted on Drupal 6 sites. Also, ideally the behavior would be standardized for all forms.

I don't really know how to fix this at all, though. I did some Googling, and the solutions out there all seem really hackish (adding a preview button out in front and hiding it from display using CSS... blech).

Comments

Frank Ralf’s picture

Version: 6.x-dev » 7.x-dev

My current installation of D7 doesn't let me use the enter key anymore in textarea fields to create multi-line entries. It did work yesterday (see screencast http://drupal.org/node/467296#comment-2095248 ).

This might be a feature to prevent un-intentional submission of a form but it steals the enter key for any other purpose like scripting for accessibility (see #467296: Accessibility improvements for vertical tabs ) which I would deem a bug.

Frank

matt_harrold’s picture

Testing Drupal 7 with latest .dev release (9th October) ... enter key does not work in the body field, the summary field ... and AFAIK ... all other textareas.

Frank Ralf’s picture

My suspect would be the following snippet from /misc/ajax.js (line 165 ff). AFAICS it's the only relevant reference to the enter key (keycode = 13) I found in core files:

// If necessary, enable keyboard submission so that AJAX behaviors
// can be triggered through keyboard input as well as e.g. a mousedown
// action.
if (element_settings.keypress) {
  $(element_settings.element).keypress(function (event) {
    // Detect enter key.
    if (event.keyCode == 13) {
      $(element_settings.element).trigger(element_settings.event);
      return false;
   }
  });
}

EDIT:
Seems to be the culprit. Deactivating this function temporarily by changing it to keyCode == 913 reinstates the usual behavior.

hth
Frank

Frank Ralf’s picture

Title: Standardize form submission behavior when "enter" key is pressed » "Enter" key deactivated (WAS: Standardize form submission behavior when "enter" key is pressed)
Priority: Normal » Critical

Changed issue title to reflect the current problem at hand and priority to "critical".

Frank Ralf’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Seems to be fixed. I'd be curious what caused the problem. There have been some recent changes to includes/ajax.inc but I can't figure out what's going on there exactly.

Damien Tournoud’s picture

Title: "Enter" key deactivated (WAS: Standardize form submission behavior when "enter" key is pressed) » Standardize form submission behavior when "enter" key is pressed
Status: Postponed (maintainer needs more info) » Active

This is still a valid issue. I would vote to disable the enter key in all textfields.

Frank Ralf’s picture

@Damien

I am skeptical whether this is a good idea.

AFAIK disabling the enter key in all textfields can have one of two purposes:

1) Prevent accidental submission of a form.
Using the enter key for form submission is also an accessibility/usability issue because forms should be usable without using a mouse.

2) Preventing line breaks
This should be handled by a filter not by disabling the enter key.

Cheers,
Frank

carlos8f’s picture

@Frank

I created #631334: Enter key disabled by ajax.js, making it impossible to use textareas properly which focuses on the bug you described. I think this issue (standardize submission behavior) is valid though and I support Damien's idea. I suspect he meant textfields as in #type=textfield, because hitting enter inside a textarea has no effect on form submission.

Frank Ralf’s picture

@carlos8f

Thanks for your input. Perhaps we should mark one of the treads as a duplicate?

Just a short general hint: The recommended method for disabling the submit behavior of the enter key is using the DOM method event.preventDefault which jQuery does a good job of making this working across browsers.

Cheers,
Frank

carlos8f’s picture

Category: bug » task
Priority: Normal » Minor

No reason to mark a duplicate. I created the new issue for ajax.js to prevent issue hijacking, because I think David Rothstein brought up something that should be addressed at some point. The ajax.js issue is a pretty bad usability flub though, because how are we supposed to write articles when we're stuck with one big paragraph :)

Frank Ralf’s picture

You're right. Perhaps I should move my stuff over to your thread ;-)

Everett Zufelt’s picture

Version: 7.x-dev » 8.x-dev

Bumping to D8. Not sure if there is still an issue here, but if there is it doesn't need to be dealt with in D7.

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

Given we have no automated js testing, I think this may be too disruptive for 8.0.x, tentatively bumping to 8.1.x.

Frank Ralf’s picture

JFTR, we had an extensive discussion about the use of the Enter key while working on #467296: Accessibility improvements for vertical tabs for Drupal 7. Please read our rationale in the following comments and take that into account when considering changes to the Enter key behavior in forms:

Kind regards,
Frank

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.