Problem/Motivation
When a form pops up in a modal window, the form includes a multi-value field and the Claro theme is in use, the "Add Another" buttons are added to the footer of the modal instead of below the input field where it belongs.
Steps to reproduce
- Enable Claro admin theme and Media/Media Library modules.
- Add a multi-value field to a media type (image), make sure the field is included in the Media Library form mode.
- Add a media reference field to a content type which uses the Media Library widget.
- Create a node of that type and add a new image in the Media Library modal.
- Note the Add Another button is in the footer of the modal rather than below the relevant field.
Same thing happens in other forms in modals using the Claro theme, such as when the Layout Builder Modal is used for Layout Builder tab.
Proposed resolution
Remove <div class="form-actions">
wrapper from around the {{ button }}
in Claro's field-multiple-value-form.html.twig
file.
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Updated Claro theme's field-multiple-value-form.html.twig file to remove 'form-actions' div wrapper around the button, which was causing the buttons to be moved to the footer when the multi-value form element appeared in a modal.
Original Post
Hi, I'm using Layout Builder Modal + Layout builder admin theme. When I use the default D8 administration theme (seven) everything works fine.
If I enable "Claro" as admin theme I've a bug: I've created a custom block type with a multivalue field. The "Add another item" button related to this field is rendered after the form submit button. This happens only with Claro so I'm reporting this bug here.
The "Add another item" should be near the field, the submit button instead should be on the bottom.
Comment | File | Size | Author |
---|---|---|---|
#81 | 3151534-D10.1.x-based-on-77--81.patch | 12.6 KB | recrit |
#81 | 3151534-D11.x-based-on-77--81.patch | 12.15 KB | recrit |
#77 | 3151534-77-reroll.patch | 12.14 KB | lauriii |
#74 | interdiff-71_73.txt | 9.11 KB | Gauravvvv |
#74 | 3151534-73.patch | 12.6 KB | Gauravvvv |
Issue fork drupal-3151534
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
FiNeX CreditAttribution: FiNeX as a volunteer commentedComment #3
jimmynash CreditAttribution: jimmynash commentedI'm seeing the same thing with Claro. On a normal node form with two multi-value entity reference fields the "Add Another" buttons get pulled into the modal footer. This is a Claro subtheme in the screenshot but I've experienced the same behavior using Claro directly.
Comment #4
jimmynash CreditAttribution: jimmynash commentedUPDATE: While this does help with some buttons in dialogs it breaks the buttons in Views UI modals in some cases.
This seems to be coming from core dialog.ajax.js
prepareDialogButtons gathers up the buttons to move to the footer using the selectors
'.form-actions input[type=submit], .layout-region-node-actions .form-actions a.button'
This is wide enough to pick up the add more buttons in the multivalue fields.
Right now I'm getting around this by:
var $buttons = $dialog.find
to something more narrow using a selector from my themeThis is the override I'm using in my theme info.yml file:
Comment #5
amykhailova CreditAttribution: amykhailova commentedWorks well for me on the default node page:
I installed Layout Builder modal and it doesn't have Admin theme option as Claro, only Seven while Claro is set as default admin and Seven is actually uninstalled.
And I can only see issue if I set Claro as front-end default - then the issue is there - but I don't think Claro is intended to be used as non-admin and also not sure that Layout Builder Modal module is intended at the moment to be used with Claro since that wasn't an option for admin themes in modules settings
Comment #6
amykhailova CreditAttribution: amykhailova commentedOh should probably have mentioned versions:
Drupal 9.0.1
And Layout Builder Modal: 8.x-1.1
Comment #7
idebr CreditAttribution: idebr at iO commentedThe issue summary mentions two separate bugs:
I suggest we fix #1 here, and fix #2 in a follow-up issue.
Comment #9
anneke_vde CreditAttribution: anneke_vde at iO commentedThe above patch fixes: "Add another item" field button is displayed as a modal action
The buttons(s) are not visible as a modal action anymore.
Comment #10
lauriiiAfter this change, there isn't sufficient margin between the button and description text.
Comment #11
komalk CreditAttribution: komalk at Srijan | A Material+ Company for Drupal India Association commentedComment #12
janmejaig CreditAttribution: janmejaig at Srijan | A Material+ Company for Drupal India Association commentedSteps To Reproduce
Note : Enable the “layout ” module under extend
This seems be working fine as expected without applying the patch for Drupal 8.9.x . Please find the attachment for the issue.
Comment #13
scotwith1tIn our case, it was the Media Library modal which revealed this problem for us. The patch in #11 worked for us too, and no problems with spacing that I could see.
Comment #14
zengenuity CreditAttribution: zengenuity at DrupalTutor / Zengenuity commentedI can confirm this issue happens Media Library, as described in #13, and the patch from #11 works to fix it.
Comment #15
quietone CreditAttribution: quietone as a volunteer commentedThanks everyone for working on this.
This is a bug and the patch in #11 is against 8.9.x, it needs to be for 9.1.x. I've started a test on 9.1.x. The issue summary should include the proposed resolution, adding the standard template would help there. And having before and after screenshots in the issue summary helps any reviewer and the committer.
In #12, janmejaig reports that they were unable to reproduce the issue. That discrepancy should be explained as well.
Does this need a test?
Comment #17
scotwith1tLooks like the patch passes for 9.1.x-dev, so I'm putting back to RTBC. Updated the summary to use the template best I could. Feel free to improve :)
Screenshots were in #11 but didn't really do it justice, so here is a before:
And an after:
As for @janmejaig report, the steps/screenshot don't seem to be relevant as it's not something in a modal, which is all this issue is concerned with, but rather something on a standard form page.
Comment #18
scotwith1tComment #19
lauriiiThis increases spacing in other use cases than field cardinality. Maybe we could just wrap the button with element that uses other class than form-actions, and we would apply the same styles for that element?
Comment #20
Premanshu CreditAttribution: Premanshu as a volunteer and at OpenSense Labs commentedComment #21
elgandoz CreditAttribution: elgandoz as a volunteer commentedThanks for this works guys, I reckon we're almost there but I can still see an issue.
While the patch fixes the issue 1 & 2, it doesn't fix the issue 3: the main form actions buttons, like the node/taxonomy "Save"/"Delete", are inconsistent with the original behaviour.
In Seven, they display correctly in the modal footer, while in Claro only the "Save" appears correctly, with "Delete" remaining in the original place.
After a quick inspection I noticed that in the standalone versions of the form (in both admin themes), case A1 & B1, "Save" is a
<input>
withclass="button"
, while "Delete" is an anchor (<a>
) withclass="button"
in Seven andclass="action-link"
in Claro.In Seven's modal (A2) the markup gets re-arranged somewhere and both links become a
<button>
, but in Claro only the first gets picked up while the second is ignored.I haven't tested if the class change is enough, but if it is, I wonder what would be the consequences in changing that class for styling and coding standards.
I will try and come with a patch soon.
Edit: I can confirm that the class change does the trick.
claro.theme@366
Commenting the snippet above fixes the modal, but obviously changes the style of the button (
class="button button--danger"
), becoming fully red.Any suggestion on the course of actions?
Maybe we could change the modifier class in order to have:
button--icon-trash
to add the trash iconbutton--action-link
(or similar) in order to simulate the "hollow" link look.Comment #22
elgandoz CreditAttribution: elgandoz as a volunteer commentedComment #23
elgandoz CreditAttribution: elgandoz as a volunteer commentedAnother solution to the above problem could be leaving the action links untouched and change the function that generates the
<button>
in the modal footer: instead of selecting the.button
class, it could select any input, button, anchor inside the.form-actions
wrapper.Comment #24
idebr CreditAttribution: idebr at iO commented#15 The issue summary contains a 'Proposed resolution'. #16 contains before/after screenshot.
#21 is a different bug: buttons that should be in the modal actions are not in the modal actions
The original issue is the inverse problem: a button is included as a modal action, but it should not be.
I suggest filing a separate issue for #21
Comment #25
elgandoz CreditAttribution: elgandoz as a volunteer commentedAs recommended by @idebr I opened a different issue for case #21, inspired by @jimmynash #4 comment.
On the current issue: I agree with @laurii in #19, to maintain the wrapper with a dedicated class in order to keep the original padding/margin without altering the component in different contexts.
Any recommendations about the naming of the wrapper class? I would propose
.subform-actions
or.multiple-value-form-actions
.The class should have the same properties of
.form-actions
, so we could change the selector like this:Comment #26
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #27
matthiasm11 CreditAttribution: matthiasm11 at MM-Experience commented+1 for patch #11.
The padding/margin should still be looked at, as stated by #19 and #25.
Comment #31
larowlanI'm not a FEFM but in my opinion, the issue here is with Drupal.behaviors.dialog.prepareDialogButtons which is using classes that are intended for styling for attaching JS behaviour (yeah I put a u in behaviour, fight me).
In my opinion a better fix would be to change that code to look for .js-form-actions and update \Drupal\Core\Render\Element\Actions::processActions to add both the .form-actions class for the styling and the .js-form-actions class for the JS functionality.
I don't think that would represent a BC risk, but happy to be wrong.
Tagging for JS to see if JS maintainers agree with me
Comment #32
larowlanComment #33
DanielVezaI need this change for a site, so protoyped the changes that larowlan suggested. It's solved the issue for me using the Claro theme.
Tests? What would need to assert? The position of the "add more" button?
Comment #34
ranjith_kumar_k_u CreditAttribution: ranjith_kumar_k_u at Zyxware Technologies commentedComment #37
JSchref CreditAttribution: JSchref commentedUsed patch #34 on 9.3.12 and it solved the problem.
Comment #38
bbu23 CreditAttribution: bbu23 at Ninja Coders commentedPatch #34 works for me as well for Drupal core 9.3.13. Thanks
Comment #39
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedComment #41
BerdirWe discovered that too and I asked about it on slack (https://drupal.slack.com/archives/C1BMUQ9U6/p1666967652891399), where @larowlan pointed me to this issue.
IMHO, changing the selector here seems problematic, I'm not sure if that's not an API change or not as we can't rely on existing markup using the js class. The Actions class seems like a perfect example for that. I proposed a different fix in slack:
@laurii confirmed that:
He also confirmed that this should be allowed as a change to Claro in a patch(?)/minor release.
We plan to work on a patch for that in the next days.
Edit/Update: I missed #25, which suggested exactly the same and even also discussed with @laurii.
Comment #42
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedI went back to the comment #25 and implemented that. #34 did not work for us, and #11 had the issue that some css rules depending on the class
.form-actions
were missing.Following #25 suggestion, I did duplicate all the css rules for
.form-actions
, for the new class. I am a bit worried that some or many of them are not actually necessary, but without a reliable way to determine which cases are happening and which are not, I made the decision to apply that everywhere.Comment #43
FMB CreditAttribution: FMB commentedApplied #34, which went fine. Didn't have the chance to test #42. Thanks!
Comment #44
BerdirNote that this breaks the paragraphs add above feature (again), as we foolishly relied on that form-actions class (to be fair, there isn't really an alternative and every theme does it differently). A patch to fix that is in #3268122: Button "Add above" is missing with Gin theme enabled
Comment #45
DeepaliJ CreditAttribution: DeepaliJ at Salsa Digital commentedVerified and applied patch #42 on Drupal 10.1.x-dev.
The patch applied cleanly.
Followed the steps mentioned in the IS and was able to reproduce the issue.
Result:
The issue got fixed after applying the patch.
The "Add another item" button is now displaying where it belongs (in this case below the 'Text' multi-valued field)
Attaching the screenshots for the reference
Before patch:
After patch:
RTBC +1
Comment #46
gaurav-mathur CreditAttribution: gaurav-mathur at Dotsquares Ltd. commentedWorking fine without applying any patch.
Comment #47
klidifia CreditAttribution: klidifia at Catalyst IT commentedLooks good and works fine. (#42)
Comment #48
larowlanWe still need tests, and it would be good to get a +1 from @lauriii
Comment #49
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #50
FiNeX CreditAttribution: FiNeX as a volunteer commented#42 works fine on my case: dialog with nested paragraphs with multiple unlimited fields. Thank you very much.
Comment #51
kevinquillen CreditAttribution: kevinquillen at Velir commentedI just applied the patch in #42 and the issue still occurs for me using Claro and Gin.
In my case, I had an actions structure within a fieldset in a form. My fix was to just remove the button from that inner actions. Then it corrected itself. Is that expected, or is there a way to prevent that scenario too?
Comment #52
BerdirI'm not sure what button that is, but it's not the regular field widget one I think. The fix here is only about the default button in field widgets by changing the class to not use form-actions. form-actions is expected to be the primary action of a form I think and should be used for others.
Comment #53
kevinquillen CreditAttribution: kevinquillen at Velir commentedYeah that is coming from a form alter (mine) where I had action buttons within a fieldset (also mine). I just removed the actions part, it moved to the right place. But I saw having more than one actions referenced here:
https://git.drupalcode.org/project/examples/-/blob/4.0.x/modules/form_ap...
I suppose one question is, shouldnt 'Add Block' be down in the action area?
Comment #55
Darren OhComment #58
Darren OhComment #61
Darren OhComment #62
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, I've tested the patch on D10.0.9 + Gin theme and it works fine. Thank you.
Comment #63
smustgrave CreditAttribution: smustgrave at Mobomo commentedPosted into #frontend channel but was previously tagged for tests which still need to happen.
Comment #64
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #65
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedComment #66
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedI have been working on a test for this issue. I am uploading the test alone, and the test together with patch #65
Comment #67
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedphpcs fixes.
Comment #68
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedComment #69
Berdirfooter is probably not the right term for this, but I'm not exactly sure what is. The class for it is ui-dialog-buttonpan, so maybe "button pane"?
description and test method hasn't been updated from the copied example. maybe testModalAddAnother()?
maybe add a comment to the assert, that we wait for the upload to finish and refer where it's copied from?
can you add a positive assert that it is where we expect it to be?
Only having not asserts means that if for example the class changes, it will still pass but no longer test what we want it to. So add a very similar elementExists() and then that will fail and we have a reminder to update.
I have no idea if we really need to change all places, but it is probably the safest option.
Comment #70
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedThanks @berdir, I addressed all your comments.
Comment #71
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedphpcs fix
Comment #73
lauriiiI think it would be nice to name this a bit more generically.. Maybe something like
field-actions
could work?Comment #74
Gauravvvv CreditAttribution: Gauravvvv at Axelerant for Drupal India Association commentedUpdated the class as per #72, attached interdiff for same
Comment #75
lauriiiRemoving "Needs frontend framework manager review" tag because I don't think this actually needs a framework manager sign-off and I have reviewed this as a maintainer of Claro. Also removing "Needs tests" because there are tests in the patch, and test only patch in #67.
Solution seems simple enough 👍 Removing
@nest
from action-link CSS is a bit of scope creep but seems at least fine by me. Claro is internal so we could probably backport this to 10.1.x as a non-disruptive bug fix.Comment #76
quietone CreditAttribution: quietone as a volunteer commentedThe patch in #74 does not apply. Can we have a reroll?
Comment #77
lauriiiSimple reroll with a conflict in
core/themes/claro/css/components/form.pcss.css
.Comment #79
lauriiiSorry for the noise.. I broke HEAD in other issue... 🤦♂️
Comment #80
recrit CreditAttribution: recrit at Phase2 commentedAttached is patch 77 rolled for 10.1.x
Comment #81
recrit CreditAttribution: recrit at Phase2 commentedUpdated patches based on #77:
- 11.x: re-rolled for latest changes to 11.x
- 10.1.x: code cleanup
Comment #83
lauriiiLooks like another random fail.
Comment #86
nod_Comment #87
nod_