Whereas conditionally hidden fields are not displayed in node edit form, they nevertheless show up on node display page if they are not empty (even if they are only filled with a default value). I use display suite module for the layout of the node display page.

Comments

Publishing Future created an issue. See original summary.

alessandrosc’s picture

Hello I tried to reproduce this problem with no luck.

Can you please write down some details of the steps we need to follow to make this issue happen and the version of display suite you are using?

Thank you!

publishing future’s picture

StatusFileSize
new41.74 KB

Thank you for looking into this! I use display suite 8.x-3.1. Please find the page layout settings in the attached screenshot.

- Add a field A (type text string)
- Add another field B (type select list)
- Got to manage dependency page and set a condition to display A only when a specific value is selected in B
- Fill A with any text to display
- Select a value in B different from the value specified as condition to show A

-> Field A is correctly hidden in node form, but value of field A shows up on node display nevertheless.
Same problem appears if A is not filled manually, but with a default value.

alessandrosc’s picture

Hi Publishing Future,

I had a look I think this was fixed in this commit https://cgit.drupalcode.org/conditional_fields/commit/?id=6c70583

I tested the latest version of the branch 8.x-1.x and it works as expected (clearing the text field if invisible).

Probably updating your module to include the latest changes will fix the issue.

Can you please try and let us know if this resolved the issue for you?

publishing future’s picture

I tested againg with Conditional Fields 8.x-1.0-alpha4+7-dev (2018-Juli-10).
However, some fields are still displayed on node display (if they are not empty) although they are set to be hidden by condition.

All these fields have default values set on node creation. However, the conditional field settings prevent all these fields from beeing visible on node form when the node is created. Nevertheless, all default values appear on node display after node creation, even if the condition for displaying them is not fulfilled.

I am not sure, whether it matters, but I can see two sub-cases that are affected:
- Check box fields (Boolean) that are triggered by a select list field.
- Select list fields that are triggered by another select list field. They partly trigger the display of a third dependent text field (string) themselves. This third field is hidden/displayed correctly.

alessandrosc’s picture

Hi Publishing Future,

I have done a patch to improve how the module handles the fields.

Select lists and checkboxes should now work better and be hidden when creating a new node.

Regarding the Check box fields (Boolean), in order to work properly, you will need to hide the label of the field and to set the 'Custom output for FALSE' to be an empty string in Manage Display settings for that field (see attached picture).

Ah last important thing: this patch contains javascript changes, so please clear your browser cache before testing it.

Let me know if this works well for you or feel free to suggest any improvements.

Thank you!

alessandrosc’s picture

Status: Active » Needs review
publishing future’s picture

Thank you very much for providing this patch and the advice regarding the Boolean fields! This helped to solve most of the problem. Now there are only two fields of special type left that are not hidden correctly on node display:

Is there a solution for these field types as well?

alessandrosc’s picture

Hi Publishing Future,

No problem at all, I had a quick look and as far as I can see the module doesn't provide support for those two custom fields type. Also adding more javascript to support them might conflict with the already supported fields.

I would suggest you to write a little custom submodule to alter the edit node form and add the code needed for your specific case (or alternatively the submodule can hide the fields in the view, it's up to you really).

I mean it's not impossible to support those new fields, but it will probably need to be discussed with the maintainers of the Conditional Fields module and it's probably out of the scope of this ticket (maybe create a new issue?).

Of course feel free to suggest any alternative if some ideas comes up in your mind.

publishing future’s picture

Thank you, AlessandroSC! I will find a workaround for these two special fields myself. It's great that we could solve the other, more general problems.

dripa’s picture

I tried this patch but it didn't work with select options. The values are still saved even if the select field is hidden.
I checked the DOM and it looks like the selected select options are not cleared, the original selected value and the "_none" options are both "selected"

avo webworks’s picture

Same as for #11. The patch doesn't work for select options.

the_glitch’s picture

The target field's value needs to be cleared when control field is controlled.

the_glitch’s picture

Maybe a patch needs to give an option to throw an alert to users which give an option to "clear all target field values" before making them disappear again.

klidifia’s picture

Version: 8.x-1.x-dev » 4.x-dev
Category: Bug report » Feature request
Status: Needs review » Needs work
StatusFileSize
new2.74 KB
new2.74 KB

Seems per #3216529: Field displays on node, even when hidden in edit form this is how it is, but I have a need to have this done and for me blanking out fields in the form and re-saving isn't appropriate, so I am checking the fields, whether they have conditions (just value conditions) and hiding the field if need be, via hook_entity_view_alter().

klidifia’s picture

klidifia’s picture

StatusFileSize
new3.08 KB

Changed from #15 as that logic wasn't picking up when single values selected which appear in the value_form part of the settings.