Currently, misc/ahah.js contains this code to trigger ajax form submission when the Enter key is pressed on the submit button:

  // If necessary, enable keyboard submission so that AHAH 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;
      }
    });
  }

I see many users expecting the same behavior when tabbing to the button and pressing the Space bar. With the current behavior, this isn't supported, and the form is submitted in the "normal" way, i.e., without AHAH's ajaxSubmit, causing a page reload.

I'm entering this as a bug on the assumption that the existing code is intended to trap all methods of form submission and re-route them to ajaxSubmit, thus preventing a page reload; on that basis, allowing a "normal" form submission via the Space bar seems like a bug.

I'm new here, so if this should have been a feature request I'm fine with changing it, of course.

Thanks,
Allen

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TwoMice’s picture

Version: 6.14 » 7.x-dev

Changing this to 7.x-dev, as I see this is still the case in misc/ajax.js.

Thanks,
Allen

brianV’s picture

Title: Usability: Allow AHAH behaviors to be triggered with spacebar » AHAH framework to check for keyCode == 32 (space bar) for ajaxSubmit behavior
Issue tags: -Usability, -ahah, -D7UX usability
FileSize
773 bytes

Patch attached.

AHAH behaviours should be triggered any time the form is submitted, and therefore should be triggered with every type of input that will submit the form.

brianV’s picture

Status: Active » Needs review
Issue tags: +Usability, +D7UX usability

Adding tags

brianV’s picture

Title: AHAH framework to check for keyCode == 32 (space bar) for ajaxSubmit behavior » Usability: Allow AHAH behaviors to be triggered with spacebar
Issue tags: +ahah

Also, simplifying title.

cosmicdreams’s picture

Title: AHAH framework to check for keyCode == 32 (space bar) for ajaxSubmit behavior » Usability: Allow AHAH behaviors to be triggered with spacebar
Issue tags: +Usability, +ahah, +D7UX usability

Patch still applies, I've tested press spacebar to submit forms on a few pages and I haven't found any ill effects yet.

rfay’s picture

Title: Usability: Allow AHAH behaviors to be triggered with spacebar » Usability: Allow AJAX behaviors to be triggered with spacebar
Issue tags: +Ajax

Updating title, adding ajax tag.

casey’s picture

Looks good to me.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

:) quickfix

rfay’s picture

Needs to be reconciled with #644158: Allow AJAX submit using space bar

brianV’s picture

#644158: Allow AJAX submit using space bar marked as a dupe of this issue, as this one is a month older.

Not that it matters which we stick with - the patch is near identical between the two of them, although one uses event.which() while the other uses event.keyCode(). Both work correctly across all major browsers.

sun’s picture

Status: Reviewed & tested by the community » Needs work

We should be using event.which(), as that is purposefully provided by jQuery. See http://api.jquery.com/event.which/ for details.

brianV’s picture

Issue tags: +Novice

@sun

Ah, learn something new every day. I guess the other approach was indeed better. Well, I'll add this one to the novice queue as I don't have time to roll a new patch myself ATM.

aspilicious’s picture

FileSize
661 bytes

still rtbc :)

aspilicious’s picture

Status: Needs work » Reviewed & tested by the community
Kiphaas7’s picture

Status: Reviewed & tested by the community » Needs review

Can't test right now, but does this _always_ submit a form when hitting spacebar, or only when the submit button has focus? The first option would be buggy behavior...

c960657’s picture

Status: Needs review » Reviewed & tested by the community

The form only submits when the submit button has focus. Setting back to RTBC.

Something along what you say actually happened in #615282: Enter key is ignored on pages with #ajax fields, though. But this is no longer an issue.

klausi’s picture

Still applies.

aspilicious’s picture

#13: event_which_spacebar.patch queued for re-testing.

aspilicious’s picture

*Retesting old patches*

rfay’s picture

I tested #13, and it works fine.

I think people expect this behavior and we should get this in.

+1 from me.

sbrattla’s picture

I've tested #13 too (on 7.0-alpha6), and I can confirm that it works fine. I think that we definately should go forward with this one.

sun’s picture

#13: event_which_spacebar.patch queued for re-testing.

sun’s picture

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

Although badly needed, this is D8 material according to the rules (I had to learn today). It may be backported at a later point in time (though that's unlikely).

rfay’s picture

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

To put it to 8.x, at least make a case for it other than "I am on a rampage", which is not adequate.

This is a community here, not just a piece of software.

And if you succeed in getting the software to work, but break the community, you have a very big net negative.

sun’s picture

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

Trust me, I know. But Drupal core maintainers only take actually required bug fixes into account for D7. Everything else is D8 material for now. I'm with you. I had to learn the hard way.

Kiphaas7’s picture

It is a bug fix, since it fixes quirky behavior. Or is there some nuance between "bug fix" and "required bug fix"?

I suppose that the patch being ridiculous small, and incredible easy aren't arguments for setting this back to 7 :)?

rfay’s picture

I agree that this is not a feature but rather a bug fix. It is definitely not an API change. This patch provides *normal*, *expected* behavior. And, of course, it's been waiting for a very long time.

Moving back to 7.x to continue the conversation.

For an issue summary, the original issue description is adequate.

Kiphaas7’s picture

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

Rfay, was your intent to set it back to 7.x dev? Because you didn't :).

obviously I'm with rfay, but still very interested to hear why sun thinks this still should be moved to 8.x.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Boy, that one fell off the radar. :\

Committed to HEAD. Thanks!

mattyoung’s picture

Status: Fixed » Active

Did anyone try this on the iPhone? iPhone [return] code is '10' so we should also be looking for '10' in addition to '13'.

c960657’s picture

Version: 7.x-dev » 6.x-dev
Status: Active » Needs review
FileSize
1.08 KB

D6 backport.

beefzilla’s picture

In which version of Drupal 6 is this bug fixed? This bug cannot be overridden with more javascript, (unlike some of the other nuisances), if you want to use the native ahah API. For those of us who have to deliver Drupal 6 modules that don't have any caveats nor addendums, patching the core isn't an option. -_-

rfay’s picture

This is in "needs review" for D6. If you'd like to get it into D6, you need to test and review it, and perhaps set it to RTBC once you've done that.

beefzilla’s picture

Status: Patch (to be ported) » Needs work

Using Windows 7, this is tested and effective in the latest versions of: FireFox, Chrome, Opera, and Safari.

IE 8, however, will both run the ahah function AND submit the form.

I'm using the version that has if(event.which == 13 || event.which == 32) btw.

beefzilla’s picture

Status: Needs review » Needs work

In response to #30, mattyoung's question - jQuery's event.which may preclude that necessity http://api.jquery.com/event.which/

beefzilla’s picture

FileSize
784 bytes

I now have this working properly in all major browsers. The problem was that when ahah is attached to a button, hitting the enter key or space bar will fire an onclick event, which ahah currently doesn't support. This happens in all major browsers, but all the GOOD browsers will catch the keypress event. Internet Explorer does not, only honoring the onclick event.

The solution is to check if the ahah object being created is associated with a button. If so, bind an onclick event. Otherwise it's business as usual. See patch.

beefzilla’s picture

Status: Needs work » Patch (to be ported)
rfay’s picture

Status: Needs work » Needs review

This is a D6 patch that you want reviewed for D6, right? Setting to "needs review".

Status: Needs review » Needs work

The last submitted patch, ahah.js_.patch, failed testing.

beefzilla’s picture

FileSize
1.13 KB

Ok, this time I read the instructions and used eclipse to make a patch using the DRUPAL6-20 branch

beefzilla’s picture

Status: Needs work » Needs review
beefzilla’s picture

FileSize
1.1 KB

God I suck at this. Did an EOL conversion in N++

Status: Needs review » Needs work

The last submitted patch, node607240-ahah.js_.patch, failed testing.

beefzilla’s picture

Status: Needs work » Needs review

Ok, I fail again. This time because I didn't apply the patch against the latest checkotu, which I assume is like a checkout, except Japanese. I looked at tags: 6.20, 6.3, and even 6.9. They all had the same ahah.js file. So I figured merging code with the most recent stable release would be a good idea, i.e. 6.20. If I really went with the latest stuff, that would be drupal 7, and that doesn't even have an ahah.js file, as it's been morphed into ajax.js.

So, I guess I should check out DRUPAL6-9 and try this again. Does that make sense, drupal admins? Somebody help the n00b get his code up in 'dere.

aspilicious’s picture

you should use 6 dev, thats the latest checkout

beefzilla’s picture

I do not see a branch or version marked "6 dev" in the cvs repo.

What am I missing? Please be extremely specific. Based on one article I've found, DRUPAL-6 is the branch for development. Is this correct?

aspilicious’s picture

According to http://drupal.org/node/97368 DRUPAL-6 is the development version.
I tried to apply it locally and it is working perfect...

Strange...

beefzilla’s picture

FileSize
1.1 KB

Thanks. I checked out DRUPAL-6, and put the same changes in against that and made a new patch. *crosses fingers* Though I didn't see a difference between patches, I can only guess the dates have changed?

beefzilla’s picture

Status: Needs work » Needs review

Ok, this is really annoying. I got this nonsense from the automated output of my last patch:

File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored.

I followed the directions for making a patch. WTF. I bet this is happening because misc/ahah.js is in the Attic - it has been removed/renamed to ajax.js in drupal 7. That's my best guess. Good thing I have my custom module rigged to automatically hack the core whenever it's installed or enabled, just to get AHAH to function properly. >:(

This is an administrative problem. The QA system is busted - my patch is simple and effective. When I flip the status to "needs work," I don't mean the patch needs work!

Status: Needs review » Needs work

The last submitted patch, node607240-ahah.js_.patch, failed testing.

c960657’s picture

The test bot currently fails all patches due to #961172: All D6 Core patches are failing.

c960657’s picture

Beefzilla, your patches for D6 contains a click handler that was not included in the D7 patch. Is that click handler relevant for D7 also, or is it only relevant in D6?

casey’s picture

Then again, spacebar isn't working on a normal non-javascript/ajax form button. Why exactly do we need to deviate from the standards?

c960657’s picture

Casey, I'm not sure I get your point? On all browsers/OS's that I know of you can press a button using the Space bar (you should move focus to the button first using the Tab key).

casey’s picture

Uhh... you're absolutely right. I didn't actually test it when I posted my previous comment, but I remember myself testing it some months ago. Apparently I did not and now I was just talking nonsense. Sorry for the false statements.

beefzilla’s picture

You, like the Dos Equis "Most interesting man in the world" probably also test your code only in production.

I have been away from this forum for a while. Wonder if my patch ever went anywhere...?

beefzilla’s picture

#48: node607240-ahah.js_.patch queued for re-testing.

c960657’s picture

I have been away from this forum for a while. Wonder if my patch ever went anywhere...?

Please see my question in #52.

rfay’s picture

Until your patch gets to RTBC it has no chance of getting committed, sadly. So work to get it to RTBC. And then it probably only has a minor chance of getting committed. You can talk with Gabor about whether it has a chance.

fearlsgroove’s picture

Issue summary: View changes
Status: Needs review » Needs work

Patch no longer applies, tabs in patch

amitgoyal’s picture

Status: Needs work » Needs review
FileSize
1000 bytes

Please review attached patch as it applies cleanly.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.