In #2829671: Implement edit perspectives with tabs when editing, tabs for perspectives were introduced. Unfortunately the implementation is not compatible with the Form API #states in Drupal core. The Form API #states property can hide certain fields depending on the value of another field. Comment #2868155-51: Add paragraph bundle to widget forms to allow easier editing of paragraph forms describes how to do that in a paragraphs subform using hook_field_widget_WIDGET_TYPE_form_alter(). However, when you load a form and the States API hides a field, paragraphs.admin.js comes along and reveals the hidden field again when it calls $parContent.show();
in the setUpTabs() function.
I think a solution should aim to hide not the fields on a tab, but a wrapper around those fields.
I'm marking this issue as major, because it is a regression and breaks compatibility with a core API.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2946856-do-not-show-hidden-elements.patch | 350 bytes | marcvangend |
|
Comments
Comment #2
marcvangendComment #3
marcvangendThis patch fixes the issue for my situation.
As you can see it's a very simple solution, even simpler than adding a wrapper like I suggested in the initial post. I have to thank @berdir for suggesting this approach. In fact, I don't quite understand why it works in the first place - if we're calling
show()
on elements that are not hidden, why are we show()ing them to begin with? But anyway, it works.If you want to reproduce the problem: I tested this patch with the combination of the lockable-behavior from the paragraphs_collection module and a form alter which looks like this:
Comment #4
hudriHad the same problem with hidden fields being revealed again, using this patch fixed it for me.
Comment #5
miro_dietikerCombining our tabs with states needs test coverage. Otherwise it will break again with future "improvements".
Comment #6
Eli-TJust a +1 for this - hit the issue where we were using states API with paragraphs, and wanted to move to the experimental widget to mitigate the clutter. This patch allowed us to do that. Thanks @marcvangend!
Comment #7
miro_dietikerPolling...
Comment #8
nsciacca+1 this worked for me and saved a headache or two, thanks!
Comment #9
carma03 CreditAttribution: carma03 commented+1 Worked successfully. Thanks!
Comment #10
Daniel Wentsch CreditAttribution: Daniel Wentsch commented+1 and thanks a lot for sharing. I was going mad because I thought my implementation of hook_conditionals_field_widget_paragraphs_form_alter was wrong.
Comment #11
aludescher CreditAttribution: aludescher as a volunteer and at Agence Inovae commented+1 this fixed states API with paragraphs edit forms in 8.x-1.5 (and also in previous versions). Thank you @marcvangend!
Comment #12
jibranCan we please commit the fix and keep the issue open to add the tests? It has been more than a year and nobody volunteered to write the tests. We might as well have a fix in the meantime.
Comment #14
miro_dietikerFinally committed (with a reroll) and create follow-up for test coverage.
Comment #16
arpitk CreditAttribution: arpitk commentedI am still facing this fields showing up issue and the patch is not working for me.