Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
As soon as a layout paragraph to be added has a validation error, it's no more possible to save the layout paragraph modal.
Steps to reproduce
This can be easily reproduced with a text paragraph:
- Create a paragraph with a text field. Set the textfield to be required.
- Add this text paragraph to a node with layout paragraphs, but don't fill any text and click "Save". A validation error pops up correctly, saying the value is required.
- Now fill in text to fix the error and try to click "Save" again. Nothing happens.
Proposed resolution
The modal action buttons have to be updated on content validation errors.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#17 | modal-broken-form-validation-3265794-14.patch | 7.92 KB | CbStuart |
Issue fork layout_paragraphs-3265794
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:
Comments
Comment #2
AnybodyComment #3
AnybodyOkay, I found the reason and an ugly workaround until this is fixed. Here are screenshots of the reproduction as written above:
Create a text paragraph and leave the required field empty:
This triggers a validation error:
The green buttons are appearing with the validation error and THEY WORK! The modal action buttons are both NOT WORKING anymore. So until this is fixed, you can click the newly added ones.
I'll leave this "Major" anyway as users might not see the workaround-buttons and this breaks core functionality of the module.
Comment #4
AnybodyComment #7
Peacog CreditAttribution: Peacog as a volunteer and at Cambrico commentedI agree that this is major since with long forms the user will not see the original form buttons unless they scroll down to the bottom of the form. The problem is caused by the fact that the original buttons are recreated by the ajax callback and have ids containing a different randomly generated section for example
edit-field-paragraphs-actions-submit--6FRd8hbaqyk
. I've created a patch that looks for the buttons by excluding the randomly generated part of the id.Comment #8
pp.panatom CreditAttribution: pp.panatom commentedThanks, patch #6 works for me.
The buttons are still "duplicated".
Comment #9
InaW CreditAttribution: InaW at Unic commentedAny Updates on this issue? I also still see the action button twice with the Patch #6
Comment #10
nicross-com CreditAttribution: nicross-com commented#6 allows the actions to be clickable again. However, as mentioned, the duplicated buttons persist.
Here is another path to reproduce this issue. If a form element has an AJAX callback which alters the entire form, then its actions will be duplicated as well. A workaround is using a more specific wrapper element than the
<form>
itself. I mention this because AJAX seems to be the general cause of this issue, not specific to validation errors:My first thought was that the patch could simply add a line to remove the new actions from the DOM. But then I considered a use case where one might alter those actions in an AJAX callback for whatever reason. So might we replace the old actions with the new ones instead? Unfortunately I can't speak to the complexity of that solution.
Comment #13
nicross-com CreditAttribution: nicross-com commentedHere's my solution in
builder.js
which moves code from thedialog:aftercreate
event handler into a reusableupdateDialogButtons()
function. We also call it within the behavior attachment so it's called after AJAX complete:Sorry about misclicking the hide button on the old issue fork. I'll try moving this into a new issue fork with ES6 as well. Please feel free to clean this up or fix edge cases. I'm still learning the Drupal JS standards and how to contribute to this project.
Comment #15
nicross-com CreditAttribution: nicross-com commentedI think I've taken this as far as I can. I don't have the ability to autogenerate the JS from ES6 source, so I did that by hand. Thanks!
Edit: I figured out the issue with the patch not applying cleanly to dev for me with composer. I needed to use the diff and not the patch. It works fine on my site.
Comment #16
NathanDanielsonCOM CreditAttribution: NathanDanielsonCOM as a volunteer commentedOur team has been doing in-depth testing of this patch with a wide range of our paragraphs, some very simple and some complex, without running into the duplicated Save/Cancel bug. We've tried various scenarios without seeing any unintended issues and are planning to take this patch into a large production site. Does anyone else have any testing feedback?
Comment #17
CbStuart CreditAttribution: CbStuart as a volunteer commentedComposer does not like the patch file for Merge Request 151 so I've recreated it. #151
Comment #20
sethhill CreditAttribution: sethhill at Aten Design Group commentedThe above approach by @nicross-com of updating the dialog buttons works as expected. In MR156 I refactored that approach to avoid setting the global variable to track the dialog, and addressed some ESLint errors that were reported in the builder.
Comment #23
justin2pin CreditAttribution: justin2pin at Aten Design Group commentedMerged MR156 – Thanks all!
Comment #25
berliner CreditAttribution: berliner commentedThe patches have been a bit greedy though. Instead of only moving the form action submit buttons and button links into the dialogs button pane, it now moves all submit buttons and button links there.
So it's now doing exactly what it was meant not to do, according to this comment: https://git.drupalcode.org/project/layout_paragraphs/-/commit/9e6ce29756...
I have raised #3442062: Dialog form button logic is too greedy as a follow-up issue to fix this.