Problem/Motivation

When a Drupal form is opened in a dialog, the submit buttons are automatically turned into jQuery UI dialog buttons.

Sometimes this is not wanted. The drupalAutoButtons options is supposed to be able to disable this feature. At the moment, setting this at FALSE from PHP doesn't do anything, buttons are still created.

Proposed resolution

Make this option work as expected from PHP. Fixing this bug should allow us to remove workarounds for this bug from off-canvas.

CommentFileSizeAuthor
#87 2793343-87.patch9.33 KBGrevil
#83 2793343-83.patch9.14 KBlauriii
#82 2793343-82-9-5-x.patch2.28 KBnaveenvalecha
#79 interdiff_75-79.txt2.35 KBbnjmnm
#79 2793343-78.patch9.39 KBbnjmnm
#76 2793343_75.patch7.96 KBbnjmnm
#73 2793343-dialog-drupalautobuttons-73.patch7.99 KBbeunerd
#57 2793343-55-d10.patch8.98 KBlauriii
#55 interdiff-53-55.txt879 bytesjustin2pin
#55 2793343-55.patch8.98 KBjustin2pin
#53 interdiff-52-53.txt523 bytesjustin2pin
#53 2793343-53.patch8.64 KBjustin2pin
#52 interdiff-51-52.txt473 bytesjustin2pin
#52 2793343-52.patch8.32 KBjustin2pin
#51 interdiff-49-51.txt12.88 KBjustin2pin
#51 2793343-51.patch8.06 KBjustin2pin
#49 interdiff-48-49.txt1.44 KBjustin2pin
#49 2793343-49.patch8.91 KBjustin2pin
#48 interdiff-44-48.txt9.54 KBjustin2pin
#48 2793343-48.patch9.33 KBjustin2pin
#45 interdiff_44-45.txt807 bytesranjith_kumar_k_u
#45 2793343-45.patch1.48 KBranjith_kumar_k_u
#44 interdiff-43-44.txt706 bytespaulocs
#44 2793343-44.patch1.77 KBpaulocs
#43 interdiff_42-43.txt677 bytesSuresh Prabhu Parkala
#43 2793343-43.patch1.75 KBSuresh Prabhu Parkala
#42 2793343-42.patch1017 bytesgints.erglis
#39 2793343-39.patch2.11 KBgints.erglis
#38 2793343-38.patch3.73 KBDaniel Kulbe
#16 dialog-drupalautobuttons-option-should-be-respected-on-initial-load-2793343-16.patch1.77 KBBram Linssen
#14 2793343-14.patch753 bytesselva.swamy@gmail.com
#6 dialog-2793343-6.patch747 bytesfinnsky
core-js-dialog-autobuttons.patch621 bytesnod_

Issue fork drupal-2793343

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_ created an issue. See original summary.

droplet’s picture

Status: Needs review » Reviewed & tested by the community

Good to see it's optional :)

tim.plunkett’s picture

Title: fix dialog drupalAutoButtons option » Dialog drupalAutoButtons option should be respected on initial load

It works for new content loaded in, amusingly enough. Just not for the initial dialog content.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We should be able to test this now.

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.

finnsky’s picture

FileSize
747 bytes

Hi all!
I met that issue when tried to manage webform inside dialog. Smth like:

hook_link_alter():
      $data_dialog_options = [
        'drupalAutoButtons' => FALSE,
        'width' => 768,
        'height' => 'auto',
        'position' => ['my' => 'top+260', 'at' => 'top'],
      ];
      $variables['options']['attributes']['data-dialog-options'] = Json::encode($data_dialog_options);

I wanted to have submit button inside webform instead dialog one.
In html that dialog link looks ok:
data-dialog-options="{"drupalAutoButtons":false,"width":768,"height":"auto","position":{"my":"top+260","at":"top"},"dialogClass":"newsletter-form"}"
https://www.drupal.org/files/issues/core-js-dialog-autobuttons.patch failed for me. My issue was because that FALSE option appears as string not boolean. It happends after AJAX submit.
That patch helped. But that issue needs some work still.

andypost’s picture

Issue tags: +JavaScript

It definitely needs tests

andypost’s picture

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

I'm sure better to find a cause of type conversion for settings withing drupal.ajax

+++ b/core/misc/dialog/dialog.ajax.js
@@ -130,9 +130,11 @@
+    if (!response.dialogOptions.drupalAutoButtons || response.dialogOptions.drupalAutoButtons !== 'false') {

when boolean converted to string?

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.

keboca’s picture

Hi guys, I noticed this patch will update code into `dialog.ajax.js` file, but I also noticed that there's a comment in the very begginning of that file, "DO NOT EDIT THIS FILE." because of this:
https://www.drupal.org/node/2815083

I would like to know what's plan for this case?

andypost’s picture

Issue tags: +Needs reroll
selva.swamy@gmail.com’s picture

@andypost Rerolled patch in latest 8.7.x DEV in the correct file.

selva.swamy@gmail.com’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
Bram Linssen’s picture

I have aded a patch that will update both `dialog.ajax.js` and `dialog.ajax.es6.js` so it works again after patching.

Status: Needs review » Needs work

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.

Anybody’s picture

Status: Needs work » Needs review
Issue tags: -JavaScript +JavaScript

@Bram Linssen see#12. Hidden #16 and #14 is the one to review. This still seems broken in latest 8.x and 9.x!

Anybody’s picture

Status: Needs review » Needs work

#14 didn't work for me, I guess
if (!response.dialogOptions.buttons || response.dialogOptions.buttons !== 'false') {
must be
if (!response.dialogOptions.buttons && response.dialogOptions.drupalAutoButtons !== 'false') {

Additionally it seems that the setting is even not respected if this function is triggered afterwards?

$dialog.on('dialogButtonsChange', function () {
      var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
      $dialog.dialog('option', 'buttons', buttons);
    });

I think we need tests for all these cases.

Anybody’s picture

Sorry I committed into the wrong branch -.- Correct Draft MR2 as cherry-pick above!

Tests are still required and missing, the MR2 now shows the planned implementation of the fix with the correct variable:
https://git.drupalcode.org/issue/drupal-2793343/-/merge_requests/2.patch

Anybody’s picture

Just tested MR2 successfully in this related issue #3191418: Set 'drupalAutoButtons' => FALSE for modal to stop all buttons being moved into modal actions and can confirm it works perfectly and fixes the bug.

I also checked the point raised in #6. It's a boolean correctly!

What's left now are tests and that's it :)

I also created a HOTFIX patch here for the dialog.ajax.es6.js AND dialog.ajax.js file if someone needs it until this is fixed:
https://git.drupalcode.org/project/drupal/-/merge_requests/222.patch

I tested it successfully with 8.9.x and 9.x!

crasx’s picture

Just tested this on my end on core 8.9 and hit a small issue.
When loading a modal via ajax, it looks like docroot/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php takes in modal options via GET and returns them with the response. When this happens, the drupalAutoButtons setting gets changed from a bool false to string false. This causes the conditional check to fail. Changing this to != "false" fixed my issue. Not sure if that is a proper solution...

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.

mglaman’s picture

I can confirm #32. false is passed as "false" from the query parameters.

Also. For some reason defining a link with buttons: [], the buttons attribute gets stripped out. And I have absolutely no idea why.

        '#attributes' => [
          'class' => ['use-ajax'],
          'data-dialog-type' => 'dialog',
          // 'data-dialog-renderer' => 'wide' throws an error.
          'data-dialog-options' => json_encode([
            'width' => 700,
            'drupalAutoButtons' => FALSE,
            // @todo drupal.ajax.js does not respect drupalAutoButtons properly,
            //   pass a dummy array until https://www.drupal.org/node/2793343.
            'buttons' => [],
          ]),

EDIT: It's not for some reason. It's a jQuery thing.

mglaman’s picture

This still isn't the best fix, because the following returns false positives (stringified false)

      if ($dialog.length) {
        // Remove and replace the dialog buttons with those from the new form.
        if ($dialog.dialog('option', 'drupalAutoButtons')) {

Gauravmahlawat made their first commit to this issue’s fork.

Daniel Kulbe’s picture

My suggestion to solve this ...

gints.erglis’s picture

Version: 9.3.x-dev » 8.9.x-dev
FileSize
2.11 KB

#14 works for me. Need a working patch for version 8.9.x, so I added this patch.

lamp5’s picture

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

Drupal 8 support has been ended.

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.

gints.erglis’s picture

Suresh Prabhu Parkala’s picture

Status: Needs work » Needs review
FileSize
1.75 KB
677 bytes

Tried to fix custom errors. Thanks.

paulocs’s picture

Here is a new patch to fix CS.

ranjith_kumar_k_u’s picture

Status: Needs review » Needs work

The last submitted patch, 45: 2793343-45.patch, failed testing. View results

justin2pin made their first commit to this issue’s fork.

justin2pin’s picture

Wow - sorry everybody for the complete mess in MR!1018. Rebasing locally against 9.4.x was obviously a mistake...

Attached is a patch against 9.4.x and an interdiff against #44.

The new patch includes:

  • Updates recommended by @DanielKulbe to correctly respect default, true, and false settings of drupalAutoButtons.
  • Fixed typos from said updates.
  • Automated tests to make sure the drupalAutoButtons option is respected.
justin2pin’s picture

FileSize
8.91 KB
1.44 KB

One more time... updated patch includes a correctly transpiled dialog.ajax.js file to ensure passes all automated tests.

justin2pin’s picture

This still needs work. Few thoughts:

  • Need to fix issue breaking ModalRendererTest when "Button pane modal!" link is clicked.
  • JS can probably be further simplified.
  • Instead of having an entirely separate test module / class, these tests should just be included in the existing dialog_renderer_test and ModalRendererTest module and class, respectively.

I'll work on an updated patch.

justin2pin’s picture

Status: Needs work » Needs review
FileSize
8.06 KB
12.88 KB

Assuming the latest patch passes tests, I think this is ready for review. A few notes/assumptions:

  • If the buttons dialog option is set, its contents will be used as dialog buttons regardless of the drupalAutoButtons option.
  • The drupalAutoButtons option defaults to true.
  • If drupalAutoButtons is true and the buttons option is empty, all form actions buttons will be moved into the jQuery UI dialog buttons area.
  • If drupalAutoButtons is set to false, form action buttons will be left as-is.
  • Tests for drupalAutoButtons option values (default, true, and false) have been added to the existing dialog_renderer_test module and ModalRenderTest class.
justin2pin’s picture

FileSize
8.32 KB
473 bytes

Minor issue with #51 - removed duplicate line response.dialogOptions = response.dialogOptions || {};.

justin2pin’s picture

FileSize
8.64 KB
523 bytes

One more re-roll -- missed transpiling the js file in the last one. Sorry for spamming the comments.

Anybody’s picture

Issue tags: -Needs tests

Thank you very much @justin2pin for looking into this, fixing things and writing the required tests. I'll remove the "Needs tests" tag now, as it now has tests!

Two things left for RTBC from my side:
1. Did you read through all the comments above like for example #6, #23, #32, #34, #36 and ensure these are fixed and have a test case?
I'm not sure if we should add tests for the stringified false and such other strange edge cases... but it might prevent us from future mistakes and misunderstandings?
From my manual tests and review, I'd say they are fixed, but this should be proofed.

2. Perhaps the following two lines should have a short inline comment explanation why this is needed or a reference to this issue? Otherwise, future developers may think this is a bug or can be cleaned up? ;)

+    } else if (response.dialogOptions.drupalAutoButtons === 'false') {
+      response.dialogOptions.drupalAutoButtons = false;
+    } else {
+      response.dialogOptions.drupalAutoButtons = !!response.dialogOptions.drupalAutoButtons;
+    }

Afterwards, this is RTBC from my perspective!
Perhaps the others here can also have a look already?

justin2pin’s picture

Thanks @Anybody! I just looked at those comments again, and I think those use cases are covered with #53. Because of the way Ajax requests are processed, the automated tests actually do test for stringified false (and only for stringified false as far as I can tell). I added addition comments in the latest re-roll, and am adding #3014136: Opening dialog via AJAX casts dialogOptions values to strings as a related issue. Just FYI, the yarn build script strips comments in dialog.ajax.js. See dialog.ajax.e6.js instead, as well as the interdiff for what changed.

Anybody’s picture

Status: Needs review » Reviewed & tested by the community

I guess "perfect" is the right word for what you did! :) Great idea to link that issue!

Just had another look and I'd see this as RTBC! Hope for a core maintainer review and feedback soon :)

lauriii’s picture

There's @todo comment mentioning this issue in \Drupal\Core\Ajax\OpenOffCanvasDialogCommand::__construct. We should either address that here or open a follow-up.

Gauravvvv’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: 2793343-55-d10.patch, failed testing. View results

Nathan Tsai’s picture

#53 looks good! Would love to see this committed :)

yogeshmpawar’s picture

Status: Needs work » Reviewed & tested by the community

Looks like test failures are unrelated.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: 2793343-55-d10.patch, failed testing. View results

Anybody’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: 2793343-55-d10.patch, failed testing. View results

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.

JeroenT’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: 2793343-55-d10.patch, failed testing. View results

Anybody’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: 2793343-55-d10.patch, failed testing. View results

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.

Hauke von Quillfeldt’s picture

I've used the last patch for Drupal 9 in combination with Layout Paragraphs and it works great.
But if i have an invalid (or required and empty) field after (ajax-)submit than the submit buttons displayed twice.
Is there any solution for that?

beunerd’s picture

beunerd’s picture

Status: Needs work » Needs review

Changing to needs review to trigger automatic testing.

Anybody’s picture

Status: Needs review » Needs work

Thanks @beunerd #73 works against 9.5.x! But has code style issues.

Could someone please finally prepare a 10.1.x MR? Hopefully we can finally fix this long outstanding issue?
For 9.5.x we should also prepare a fix.

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
7.96 KB

Status: Needs review » Needs work

The last submitted patch, 76: 2793343_75.patch, failed testing. View results

Anybody’s picture

#76 works for Drupal 10.0 - thanks @bnjmnm! We're close here, only 2 failing tests left!

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
9.39 KB
2.35 KB
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs followup +Needs Review Queue Initiative, +Needs issue summary update

Removing the needs follow up as it seems the todo mentioned in #57 is being addressed.

Think the issue summary could use some love though.

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.

naveenvalecha’s picture

Here's the 9.5.x patch only for the project I'm on

lauriii’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
FileSize
9.14 KB

Here's a rerolled version for 11.x. Also updated the issue summary.

Gauravvvv’s picture

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Tested this using the module provided dialog_renderer_test
Went to /dialog_renderer-test-links (like the test)
Verified Auto buttons default! and Auto buttons false! both contained .ui-dialog-buttonpane without the fix

With the fix only the first link contained .ui-dialog-buttonpane.

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

This basically looks good, but I see a risk of introducing an intermittent test failure. Lets get that addressed and I bet this is good to go. It's simple enough that if the person who addresses it is comfortable with the change they can self-switch this back to RTBC.

+++ b/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php
@@ -74,6 +74,29 @@ public function testModalRenderer() {
+    $this->clickLink('Auto buttons default!');
+    $session_assert->assertWaitOnAjaxRequest();
+    $session_assert->elementExists('css', '.ui-dialog-buttonpane .ui-dialog-buttonset .js-form-submit');
+
+    // When the drupalAutoButtons option is false, buttons SHOULD NOT be moved
+    // into the 'ui-dialog-buttonpane' container.
+    $this->drupalGet('/dialog_renderer-test-links');
+    $this->clickLink('Auto buttons false!');
+    $session_assert->assertWaitOnAjaxRequest();
+    $session_assert->elementExists('css', '.form-actions');
+    $session_assert->elementNotExists('css', '.ui-dialog-buttonpane');
+
+    // When the drupalAutoButtons option is true, buttons SHOULD be moved
+    // into the 'ui-dialog-buttonpane' container.
+    $this->drupalGet('/dialog_renderer-test-links');
+    $this->clickLink('Auto buttons true!');
+    $session_assert->assertWaitOnAjaxRequest();
+    $session_assert->elementExists('css', '.ui-dialog-buttonpane .ui-dialog-buttonset .js-form-submit');

assertWaitOnAjaxRequest to wait on a modal opening risks intermittent test failures. jQuery UI can continue to manipulate the elements after Drupal AJAX is done. For a simple use like this there isn't that much risk.. but given the number of test runs that happen daily it's best to be cautious. If this can instead waitForEementExists on whatever element needs to appear for testing to continue, then it should be fine.

Grevil’s picture

Rerolled on current 11.x and switched out $session_assert->assertWaitOnAjaxRequest() in favour of $this->assertNotNull($session_assert->waitForElement() as suggested in #86.

Let's see if tests still succeed.

Grevil’s picture

Grevil changed the visibility of the branch Anybody-2793343-dialog-drupalautobuttons-option-patch-94463 to hidden.

Grevil changed the visibility of the branch 2793343-drupalAutoButtons to hidden.

Grevil changed the visibility of the branch cherry-pick-e3ae816e to hidden.

Grevil changed the visibility of the branch 9.2.x to hidden.

Grevil’s picture

No idea, why my patch did not pass tests, created another branch and MR with patch #87 applied here: https://git.drupalcode.org/project/drupal/-/merge_requests/6288

Let's see what the tests from the gitlab-ci are saying.

finnsky’s picture

@Grevil

https://www.drupal.org/project/drupal/issues/3401988

you need to update fork 11.x

Grevil’s picture

@finnsky thanks! The fork doesn't even have 11.x haha, going to update it ASAP.

EDIT: Running again.

Grevil changed the visibility of the branch 11.x to hidden.

Grevil’s picture

Status: Needs review » Reviewed & tested by the community

All green!

From #86:

It's simple enough that if the person who addresses it is comfortable with the change they can self-switch this back to RTBC.

->Done

  • lauriii committed 77888cf5 on 11.x
    Issue #2793343 by justin2pin, Anybody, Grevil, mglaman, bnjmnm,...

  • lauriii committed bbbf7138 on 10.2.x
    Issue #2793343 by justin2pin, Anybody, Grevil, mglaman, bnjmnm,...
lauriii’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 77888cf and pushed to 11.x. Also cherry-picked to 10.2.x as a non-disruptive bug fix. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.