Enable attached example module and go to /triggering-elements

In Chrome go over the tabs and click enter (i.e. don't click with the mouse). The $form_state['triggering_element']['#value'] changes according to the selected tab.

In Firefox go to the second tab and hit enter. $form_state['triggering_element']['#value'] is the first button instead of the second.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Try disabling Javascript and you will see that the behavior remains the same.

It's a browser issue, and a very messy one. HTML5 has some nothing to say on this issue:

User agents may establish a button in each form as being the form's default button. This should be the first submit button in tree order whose form owner is that form element, but user agents may pick another button if another would be more appropriate for the platform.

"May", "May pick another", ...

amitaibu’s picture

So you say we should change the variable name to "#it-might-be-the-triggering_element" ? ;)

Damien Tournoud’s picture

It is the triggering element alright. It's just that each browser have a different notion of what is the default button associated with a text field.

amitaibu’s picture

The problem that I had with it, was when I wanted to use #limit_validation_errors. So in the end I gave all the submit buttons the same #limit_validation_errors so it will validate only what is really needed.

I guess this issue should be about writing a patch to document the fact that #triggering_element is browser specific.

amitaibu’s picture

Title: Different $form_state['#triggering_element'] on different browsers » Document different $form_state['#triggering_element'] on different browsers
Category: bug » task
Status: Active » Needs review
FileSize
753 bytes

Little docs about this.

rfay’s picture

This has been brought up before, and I *think* it's a general web-wide problem with browsers not being consistent. I've fought with it quite a lot (I hate the performance settings page because I always hit enter to submit, and it clears the cache instead of saving my settings.)

I suppose we could do something about this with javascript, but not sure there's a general solution. However, I'm certainly not a wise one in this area.

amitaibu’s picture

A bit better docs.

rfay’s picture

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

Hmm. $form_state['clicked_button'] is obsolete ($form_state['triggering_element'] has replaced it. So in 8.x we should remove 'clicked_button' completely from the doc.

Moving this to 8.x since it has to be done there first.

I don't have an objection to documenting this in the AJAX stuff (I don't think) but I don't think this problem has anything to do with Drupal.

amitaibu’s picture

> I don't think this problem has anything to do with Drupal.

I agree it's not a Drupal bug, but still I think a line or two can help people understand why their form isn't submitted as they might expect.

rfay’s picture

Issue tags: +Needs backport to D7
amitaibu’s picture

@rfay,
Your comment on #10 is empty?

amitaibu’s picture

Issue tags: -Needs backport to D7

#7: 1153960-trigger-element-7.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, 1153960-trigger-element-7.patch, failed testing.

Everett Zufelt’s picture

+ * and is also used in Ajax handlers. Note that the value of the triggering
+ * element after a user pressed the enter key is browser specific, as the HTML
+ * does not specify clear enough which element should be selected as the

Note that the value of the triggering element after a user presses the enter key is browser specific, as HTML does not provide a mechanism to specify which button to use as the triggering element.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Tested on safari, chrome, and firefox and not seeing any issue with the states.

If still a valid task please reopen updating issue summary to reflect D10

Thanks!