If an end user makes a target field visible by clicking on a control field then puts values in and then changes their mind and unchecks the control field, the target fields are hidden with the values still there ready to be saved to the node when in fact they're actually not wanted.

I've tried to remedy this problem by setting up a new condition to remove the values from the target field when the control field is set to any particular state. This doesn't work because when it will not 'Add Dependency' when you try to advance to save the dependency.

Comments

the_glitch created an issue. See original summary.

the_glitch’s picture

Issue summary: View changes
xxronis’s picture

Indeed, the scenario you describe should be covered by the "// On invisible make empty and unrequired." binding, in conditional_fields.js but that doesn't work.

The simplest scenario actually, with a target being unchecked when the trigger is unchecked does not work, tried all combinations (unchecked, value set up)

playful’s picture

Same issue.

xxronis’s picture

This will kind of work for the checkbox going invisible, but its not great.
I believe the error comes from core states.js on.checked func

the_glitch’s picture

@xxronis What does the patch do exactly?

xxronis’s picture

It unchecks a target checkbox when it goes invisible. Setting a target boolean input as invisible in a condition should empty its value- if previously checked.

the_glitch’s picture

OK great. I'll give it a try once all the other drupal issues are out of the way.

the_glitch’s picture

Just tried adding a boolean as a control field to an image field. (Off state = invisible image field, on state = visible image field)
I added an image then turned the boolean to 'off' but image doesn't delete so the image saves to the node anyway.

the_glitch’s picture

Patch #5 doesn't work

xxronis’s picture

@the_glitch Hold on, this (my patch at least) is about unchecking a previously checked and visible CHECKBOX, when another control field goes "Off" and the target goes invisible. Don't see how this would work for your image field to get emptied! this is for 2 dependent checkboxes (inputs), not some field with value, its only for booleans..

My scenario is:
Two checkboxes, when the trigger is unchecked, the target must go invisible and unchecked.
Checking the target, and then unchecking the trigger, must save my node with target value = false even if I had it checked (true) when visible.

Re-reading your description maybe I misunderstood. You probably need to clarify what target fields you mention here

Thanks

Sushma Gogula’s picture

I have recently upgraded to 8.x-1.0-alpha6 from 8.x-1.0-alpha5. However, I am also facing the similar error.

In this scenario, "Locations" field is dependent on "All Locations" field.
So, If "All Locations" is selected then "Location" field should not get saved and should get emptied. But, in this case it is saving both control field and target field, which is not expected.

Please advise if there are any workarounds or patches for this issue available already?

the_glitch’s picture

Welcome to Drupal Sushma. I see you're in Australia. Come join the Drupal Slack. There's an Australian channel and a support channel you'll probably find very useful.

Sushma Gogula’s picture

Thanks @the_glitch. I will join and post this there.

the_glitch’s picture

Hi xxronis

Yes your patch works well for unchecking checkboxes but if that checkbox is a control field that controls the visibility of another field, which holds a value such as an integer, then that other field's value isn't also cleared.

This is an important bug to address because if the checkbox is deselected by the function of the patch, then a user would assume that the value field that now isn't visible would also be cleared.

So to give you an idea of what I mean with the hierarchical structure:
- Taxonomy (select field with 2 taxonomy terms as control values)
- Checkbox (Boolean)
- Integer (variable input)

Taxonomy value 2 sets Checkbox to off, but off still needs to clear Integer value.

rajdeep0826’s picture

StatusFileSize
new1.09 KB
the_glitch’s picture

@rajdeep0826 if your patch #16 is supposed to clear values in fields, when their state is made invisible, I'm afraid your patch doesn't work.

And if it's supposed to be unchecking checkboxes when that checkbox's state is invisible, there's already a working patch here for that.

prudloff’s picture

StatusFileSize
new1.56 KB
new852 bytes

I think the script should restore the value when the checkbox is visible again or it is confusing for users.
I updated the patch to store the checked value and restore it.

prudloff’s picture

Status: Active » Needs review
hmendes’s picture

Hello!
Isn't this issue duplicated from # 2833343 -Re-add reset to default values option ?

gaëlg’s picture

Status: Needs review » Closed (outdated)

@hmendes: Yes, I think so.