Problem/Motivation

When filling out the register new user form, it should be possible to press enter to submit the form. Right now, this is not possible, if the form includes the "user picture" field (which it does by default in the standard profile). With javascript enabled, simply nothing happens.

This also has the added side effect that if you press enter without javascript enabled, the form gets submitted, but you don't get any error messages.

If i disable the user picture field, the form can be submitted with the enter key both with and without javascript enabled.

Some gifs attached to illustrate.

I looked quickly through the javascript, and it seems that because the element of the picture has the property element_settings.prevent set to click, it disables click, and everything stops working.

The preventing of click happens in ajax.js line 287.

I have not yet tested, but I assume this maybe also applies to all forms with file fields with ajax attached to them?Just tested. This applies to a node form with either file or image field attached also.

Proposed resolution

Not sure yet

Remaining tasks

Fix it :)

User interface changes

Not sure yet.

API changes

Hopefully none?

CommentFileSizeAuthor
#1 register-no-js-pic.gif208.49 KBeiriksm
#1 register-no-js.gif366.08 KBeiriksm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eiriksm’s picture

FileSize
366.08 KB
208.49 KB
eiriksm’s picture

Title: Not possible to submit user create with pressing ENTER, if form has a user picture field » Not possible to submit forms with pressing ENTER, if form has a file field
Issue summary: View changes
eiriksm’s picture

Issue summary: View changes
nod_’s picture

I'm afraid it's a "feature".

When hitting Enter in a form, the browser will look for the default button and "click" that. From the spec:

A form element's default button is the first submit button in tree order whose form owner is that form element.

https://html.spec.whatwg.org/multipage/forms.html#implicit-submission

In the case where there is an image element, the default button is the upload field, not the form submit button. Unfortunately that upload field is also the one on which click is prevented.

All this is up to browsers and we shouldn't be messing with it in core. This is a won't fix for me.

eiriksm’s picture

When I discovered this, I saw it on a user registration form. So I tried the user registration on Drupal 7 and pressed enter. That worked. So it seemed like a clear regression to me.

Now that I know this is actually because of the file field form I was able to reproduce this on Drupal 7 as well. So clearly not a regression. More maybe a "feature" then, I guess.

As for the wontfix. Well. I can think of at least a couple of hacks and workarounds for this. Some probably more hacky than others:

- Change the type of the input to button. This will unfortunately break uploading for no-js, so probably a bad idea.
- Change the type of the input to button with javascript. Very hacky, but this actually works. Does not break any existing functionality, only adds the possibility to press enter for js-users (most people).
- Prepend a hidden submit button before the first file button. So hacky.
- Instead of disabling click, try to observe the actual event and not blindly return false (did not try this).

That being said. All of these "solutions" could probably live in a contrib module. I was just writing the first few things that came to mind.

Thoughts?

nod_’s picture

Pretty much agree with you.

Change type: no.
Change type with JS: no, I'm worried about a11y in that case. And who knows what browsers will do with the file input, better not get in their way.
Prepend hidden: no.
Observing event: there is no difference between an enter click and a click click. And that would mean redirecting a click to another button, not a fan.

Contrib +1

eiriksm’s picture

Status: Active » Closed (won't fix)

Change type with JS: no, I'm worried about a11y in that case. And who knows what browsers will do with the file input, better not get in their way.

I actually tested this. It works. But still, pretty hacky stuff. Regarding a11y, isnt being able to submit with enter also an a11y consideration? Not sure which is worse here.

Anyway, I'm going to close it as wont fix.

alexpott’s picture

Status: Closed (won't fix) » Active
Issue tags: -JavaScript +JavaScript

This issue has an "interesting" effect.

Do the following:

  • Install standard
  • Login in as a user that can create content
  • Visit node/add/page - enter text in the title field and press enter to finish entering the it - the node will save and you'll end up on node/1
  • Visit node/add/article - enter text in the title field and press enter to finish entering the it - the node will not save and nothing will happen.

I'm really really not sure what the correct solution is here or whether we want a solution but the behaviour is odd and very hard to explain to a user.

quietone’s picture

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

Moving to supported version.

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.