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.
Comment | File | Size | Author |
---|---|---|---|
#87 | 2793343-87.patch | 9.33 KB | Grevil |
#83 | 2793343-83.patch | 9.14 KB | lauriii |
#82 | 2793343-82-9-5-x.patch | 2.28 KB | naveenvalecha |
#79 | interdiff_75-79.txt | 2.35 KB | bnjmnm |
#79 | 2793343-78.patch | 9.39 KB | bnjmnm |
|
Issue fork drupal-2793343
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:
- 2793343-dialog-drupalautobuttons-option-final changes, plain diff MR !6288
- 11.x compare
- Anybody-2793343-dialog-drupalautobuttons-option-patch-94463 changes, plain diff MR !222
- 2793343-drupalAutoButtons changes, plain diff MR !1018
- cherry-pick-e3ae816e compare
- 2793343-dialog-drupalautobuttons-option changes, plain diff MR !1
- 9.2.x compare
Comments
Comment #2
droplet CreditAttribution: droplet commentedGood to see it's optional :)
Comment #3
tim.plunkettIt works for new content loaded in, amusingly enough. Just not for the initial dialog content.
Comment #4
alexpottWe should be able to test this now.
Comment #6
finnsky CreditAttribution: finnsky at Skilld commentedHi all!
I met that issue when tried to manage webform inside dialog. Smth like:
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.
Comment #7
andypostIt definitely needs tests
Comment #8
andypostI'm sure better to find a cause of type conversion for settings withing drupal.ajax
when boolean converted to string?
Comment #12
keboca CreditAttribution: keboca as a volunteer commentedHi 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?
Comment #13
andypostComment #14
selva.swamy@gmail.com CreditAttribution: selva.swamy@gmail.com as a volunteer and commented@andypost Rerolled patch in latest 8.7.x DEV in the correct file.
Comment #15
selva.swamy@gmail.com CreditAttribution: selva.swamy@gmail.com as a volunteer and commentedComment #16
Bram Linssen CreditAttribution: Bram Linssen as a volunteer commentedI have aded a patch that will update both `dialog.ajax.js` and `dialog.ajax.es6.js` so it works again after patching.
Comment #22
Anybody@Bram Linssen see#12. Hidden #16 and #14 is the one to review. This still seems broken in latest 8.x and 9.x!
Comment #23
Anybody#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?
I think we need tests for all these cases.
Comment #29
AnybodySorry 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
Comment #30
AnybodyJust 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!
Comment #32
crasx CreditAttribution: crasx as a volunteer and at Bounteous commentedJust 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...
Comment #34
mglamanI 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.EDIT: It's not for some reason. It's a jQuery thing.
Comment #36
mglamanThis still isn't the best fix, because the following returns false positives (stringified false)
Comment #38
Daniel KulbeMy suggestion to solve this ...
Comment #39
gints.erglis CreditAttribution: gints.erglis as a volunteer commented#14 works for me. Need a working patch for version 8.9.x, so I added this patch.
Comment #40
lamp5Drupal 8 support has been ended.
Comment #42
gints.erglis CreditAttribution: gints.erglis as a volunteer commentedComment #43
Suresh Prabhu Parkala CreditAttribution: Suresh Prabhu Parkala at Specbee commentedTried to fix custom errors. Thanks.
Comment #44
paulocsHere is a new patch to fix CS.
Comment #45
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedComment #48
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedWow - 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:
Comment #49
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedOne more time... updated patch includes a correctly transpiled dialog.ajax.js file to ensure passes all automated tests.
Comment #50
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedThis still needs work. Few thoughts:
dialog_renderer_test
andModalRendererTest
module and class, respectively.I'll work on an updated patch.
Comment #51
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedAssuming the latest patch passes tests, I think this is ready for review. A few notes/assumptions:
buttons
dialog option is set, its contents will be used as dialog buttons regardless of thedrupalAutoButtons
option.drupalAutoButtons
option defaults to true.drupalAutoButtons
is true and thebuttons
option is empty, all form actions buttons will be moved into the jQuery UI dialog buttons area.drupalAutoButtons
is set to false, form action buttons will be left as-is.drupalAutoButtons
option values (default, true, and false) have been added to the existingdialog_renderer_test
module andModalRenderTest
class.Comment #52
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedMinor issue with #51 - removed duplicate line
response.dialogOptions = response.dialogOptions || {};
.Comment #53
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedOne more re-roll -- missed transpiling the js file in the last one. Sorry for spamming the comments.
Comment #54
AnybodyThank 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? ;)
Afterwards, this is RTBC from my perspective!
Perhaps the others here can also have a look already?
Comment #55
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedThanks @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.
Comment #56
AnybodyI 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 :)
Comment #57
lauriiiThere's @todo comment mentioning this issue in
\Drupal\Core\Ajax\OpenOffCanvasDialogCommand::__construct
. We should either address that here or open a follow-up.Comment #58
Gauravvvv CreditAttribution: Gauravvvv at Srijan | A Material+ Company commentedComment #60
Nathan Tsai CreditAttribution: Nathan Tsai at Alberni Design commented#53 looks good! Would love to see this committed :)
Comment #61
yogeshmpawarLooks like test failures are unrelated.
Comment #63
andypostSend retest
Comment #64
AnybodyComment #67
JeroenTComment #69
AnybodyComment #72
Hauke von Quillfeldt CreditAttribution: Hauke von Quillfeldt at yousign GmbH commentedI'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?
Comment #73
beunerd CreditAttribution: beunerd commentedHere's a patch for 9.5
Comment #74
beunerd CreditAttribution: beunerd commentedChanging to needs review to trigger automatic testing.
Comment #75
AnybodyThanks @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.
Comment #76
bnjmnmComment #78
Anybody#76 works for Drupal 10.0 - thanks @bnjmnm! We're close here, only 2 failing tests left!
Comment #79
bnjmnmComment #80
smustgrave CreditAttribution: smustgrave at Mobomo commentedRemoving the needs follow up as it seems the todo mentioned in #57 is being addressed.
Think the issue summary could use some love though.
Comment #82
naveenvalechaHere's the 9.5.x patch only for the project I'm on
Comment #83
lauriiiHere's a rerolled version for 11.x. Also updated the issue summary.
Comment #84
Gauravvvv CreditAttribution: Gauravvvv at Axelerant for Drupal India Association commentedComment #85
smustgrave CreditAttribution: smustgrave at Mobomo commentedTested 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.
Comment #86
bnjmnmThis 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.
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 insteadwaitForEementExists
on whatever element needs to appear for testing to continue, then it should be fine.Comment #87
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedRerolled 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.
Comment #88
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedComment #94
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedNo 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.
Comment #95
finnsky CreditAttribution: finnsky at Skilld commented@Grevil
https://www.drupal.org/project/drupal/issues/3401988
you need to update fork 11.x
Comment #96
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commented@finnsky thanks! The fork doesn't even have 11.x haha, going to update it ASAP.
EDIT: Running again.
Comment #98
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedAll green!
From #86:
->Done
Comment #102
lauriiiCommitted 77888cf and pushed to 11.x. Also cherry-picked to 10.2.x as a non-disruptive bug fix. Thanks!