Needs work
Project:
Conditional Fields
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
5 Oct 2009 at 20:03 UTC
Updated:
1 Feb 2023 at 17:45 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #1
capellicI had the same problem and solved it by setting up two rules with the Rules module -- one for when the value of the controlling field was "file" and one for when it was "link."
Here are the details for when "file" was selected by the controlling field:
1. Set the event for "Content is going to be saved"
2. Add a "If" condition defined as "Field has value". Leave the fields in the "Arguments configuration" fieldset as they are and select your conditional field in the "Field" drop-down and click Next.
3. You will see the CCK widget on the next page. Select "File" and click Save.
So at this point, we have the rule firing off any time that this form is saved and the controlling field is set to "file".
4. Add an action defined as "CCK, Populate Field" and click Continue.
5. Select the field holding the linked value and click Continue.
6. Yo wile see the Link field. Leave it blank. Click Save.
7. Done.
Comment #2
aac commentedThanks capellic.
Your method works fine. But if the link(url) field is "REQUIRED" then you would not be able to save the action part of the rule.
Comment #3
capellic@aac. Yeah, I haven't tried to make dependent fields required. I required the controlling field and, the way my forms are laid out and I only have one controlled field, users get the impression that the controlled field is required, too. And as you've probably assumed, I also use Rules to enforce that the controlled field be required. I first turn on validation for that form. Then I look at the value for the controlling field and if it is X and there isn't at least one value for X (setup for multi-value fields), then thrown an error.
IF NOT:
DO:
Set form error on element 'field_event_more_info' with message, "You must define a link."
Comment #4
peterpoe commentedFrom what I undertand, this is a problem with the layout of the form and not of Conditional Fields?
The behavior with the values of controlled fields, is that while editing a node, the values of those untriggered are mantained. This is for user conveniency. But, when you save the node, the values of untriggered controlled fields will be reset to their default values, unless you uncheck the corresponding option in the Conditional Fields options tab.
Feel free to reopen if you think this actually a feature request.
Comment #5
xjmHmm, what you describe in #4 is not what happened when I originally opened this issue. Values were saved regardless. I'll test it again.
Comment #6
capellicJust revisiting this after all these years. I have "Reset the dependent to its default values when the form is submitted if the dependency is not triggered." checked. I also see this, "Note: This setting only applies if the condition is "Value" and may not work with some field types. Also, ensure that the default values are valid, since they will not be validated." My condition is a "Value" so it should work, but it does not, in two cases. I have a dependent field that is a file and another that is a link-- neither get cleared out when not visible and the form is saved.
Comment #7
capellicComment #8
doppel commentedSame issue here.
I got my taxonomy term reference
Facebook
Twitter
Google Plus
Others
when I tick others field the Others Field is appearing but when I untick the others field, the value of the others field was not cleared even if the reset to default value check box in the dependency config was ticked.
Comment #9
sashken2 commentedI have same issue too.
Comment #10
gaurav_drupalSame issue.
Comment #11
Coupon Code Swap commentedI am also having the same issue. It used to work properly, if a value was left in a field that got hidden, it would be reset to default upon saving. Not sure exactly when it stopped working. Now, it maintains the value that is lingering in the hidden field after saving the node instead of resetting it to default so that both the visible and hidden fields have saved values.
Note: This is a problem with 7.x-3.0-alpha2. I just reverted back to 7.x-3.0-alpha1 and reset to default is working properly again.
Comment #12
oo0shiny commentedIt looks like the update in 7.x-3.0-alpha2 to line 737 in conditional_fields.module is the culprit here. The if statement was changed from
$parents = isset($element['#field_parents']) ? $element['#field_parents'] : $element['#parents'];to
$parents = !empty($element['#field_parents']) ? $element['#field_parents'] : $element['#parents'];Reverting this line of code makes everything work again in terms of removing the field on the hidden value. I've added a patch that does just this, let me know if it fixes the issue. I'm not sure why this changed, so I'm curious if it's broken anything else. I can't find any other issues in my brief testing.
Comment #13
oo0shiny commentedComment #14
oo0shiny commentedUpdating patch name with correct syntax based on these guidelines: https://www.drupal.org/patch/submit
Comment #15
peterpoe commentedCan't just revert that change: it would break #1542706: Conditional fields not saving
Comment #16
webbymatt commentedCan confirm that #14 works, I've just deployed to a live site without issue. Bit of a lifesaver, actually!
Comment #17
sergei_brill commentedThe patch works for me.
Comment #18
suneethark commented#14 patch works for me. Thanks for the patch.
Comment #19
toki#14 patch works for me too. Reset the dependent (term reference field) after cloning a content and changing a dependency value (term reference field too) now works (the dependent value back to default). No problem with saving.
Comment #20
Coupon Code Swap commentedPatch #14 works for me as well. Perhaps it should be committed to next release.
Comment #21
br0kenComment #22
vasike#14 patch won't apply
But #21 will
I confirm that the #14 approach fix the issue i have with Term reference fields.
@BR0kEN: could you, please, detail what your patch brings to this fix?
Maybe some example to replicate a case for this fix.
Is it about #15 comment?
p.s. It seems there are other similar issues open.
Maybe we could focus on this one or other only
#1306096: Problem with "Reset the dependent to its default values if the dependency is not triggered."
or
#2781493: Reset dependent to default values not working
Comment #23
casperone commentedHi,
I am pretty new to drupal and having a heck of a time trying to apply patch #21. I attached a picture of the error I am getting, is anyone willing to point me in the direction?
My goal is to use conditional fields to set the value of a field to "Emptied" based on a dependency OR use the "Reset the dependent to its default values if the dependency is not triggered" function, neither of which seem to be working.
Currently running:
Drupal 7.56
MySQL 5.6.33
PHP 5.6.30
Thanks!
Comment #24
capysara commentedHas anyone already tested if #21 addresses the fix in #1542706: Conditional fields not saving?
Comment #25
sashken2 commentedI have same issue in Drupal 8
Comment #26
colanThis looks like a feature request. New features go into HEAD, and may then be backported.
Comment #27
paulocsI did a patch for it.
I attached it in the issue #2833343: Re-add reset to default values option. May be you can test it for me. Thanks!
Comment #28
crutch commented+1 #21 Thank you
Comment #29
nicholassI accomplished this pretty easily in D9 with https://www.drupal.org/project/eca Similar to #1.
Wish it was in the module itself but all the patches here are for D7