Closed (fixed)
Project:
Conditional Fields
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Dec 2018 at 23:59 UTC
Updated:
23 May 2023 at 18:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
c.e.a commentedAny update on this issue please!
Comment #3
snehalgaikwad commentedStarting work on patch for this.
Comment #4
c.e.a commentedthank you for your time, waiting for the patch
Comment #5
c.e.a commented@snehalgaikwad thank you for your support, I would like to ask if there is a working in progress for the patch ?
If you have free time available of course
Comment #6
snehalgaikwad commentedComment #7
markdcI'm having a similar problem with a select box not being emptied.
Comment #8
phonkala commentedAny progress with this? Same problem here and I noticed there is quite similar issue too: https://www.drupal.org/project/conditional_fields/issues/2918601
In my case I have a select list "Sign-Up Type" with multiple options, including "Built-In Webform" and "Custom Webform". I also have 2 additional select lists "Built-In Webforms" and "Custom Webforms" that both include a list of webforms specific for each sign-up type. This way user can choose which type of sign-up to use (in their events) and the webform lists are hidden accordingly, so if user chooses sign-up type of "Custom Webform", the "Built-In Webforms" list is hidden. That works perfectly.
The problem is that when doing exactly the same thing but with the intention to actually "empty" the other webform list, it just does nothing. For example again, if the user has chosen sign-up type of "Custom Webform", the "Built-In Webforms" select list should be hidden (works) but also be "emptied" (does not work). Using "Filled with a Value" and manually entering desired value does nothing either.
I tested both the "Filled with a value" and "Emptied" actions with multiple sets of different types of target and source fields, even plain text fields and none worked at all. Making fields visible/invisible with exactly same conditions worked every time. Hope this helps even a bit, the issue seems pretty major to me as it's a huge part of the idea of conditional fields functionality. Sadly I'm not experienced enough with Drupal 8 development I could be much of help here.
Comment #9
abhisekmazumdarHi, @snehalgaikwad I'm Picking this up. If there any update from your side can let me know.
Thank You
Comment #10
abhisekmazumdarHi,
The field gets emptied now, but the value is not getting preserved. I would need some suggestion about what should be the approach for preserving the value.
For now, I have added a patch with proper validation if Target Filed is required or not.
Comment #11
nikunjkotechaHi Abhisek,
We shouldn't change the text used in t() if not required, this change would required update in translations that are already added in a site using this module.
Please justify the need of this change or revert it.
Comment #12
nikunjkotechaComment #13
abhisekmazumdarThanks, @nikunjkotecha for the inputs.
The validation for the
setErrorByNamewill be fixed on Invalid placeholder (!field). So I have removed it from my patch.Comment #14
nikunjkotechaPatch looks good to me.
Comment #15
abhisekmazumdarUpdated the patch, now it Restores previous value.
Comment #16
abhisekmazumdarComment #17
divya.sejekan commentedComment #18
divya.sejekan commentedI have tested the patch. And the issue is resolved.
Comment #19
divya.sejekan commentedComment #20
phonkala commentedHey there!
Haven't had the possibility to test the patch yet but checked the code.
I would believe using only .val() function won't solve the problem in every case: as far as I know, it only works when the element can have value attribute and the value shown is based on that (like input fields).
You propably need to use some .attr("selected") function for select elements, .attr("checked") function for radio buttons / checkboxes etc. Or if I remember correctly, in jQuery you can also use .toggle() in these cases.
Also, textarea doesn't use value attribute to show the contents of the element but the content is written between <textarea> tags, not sure though if in jQuery it can be set using .val(). But as said, haven't been able to test this, just a notice and something to test.
Comment #21
playful commentedI tried #15 with autocomplete and text fields as the targets with a checkbox as controller. The target field is successfully emptied, however the target field also emptied each time the node edit form page is loaded.
It does not work with address field as target.
Comment #22
playful commented#15 also introduces some other strange behavior. To reproduce, set two text fields as targets to be invisible when a boolean checkbox controller field is unchecked. In the form, each time the controller is unchecked, only one of the target fields becomes invisible. The checkbox must be checked and unchecked multiple times to iterate through each target field.
Seems like a simple misplacement of a foreach/while loop.
Comment #23
abhisekmazumdarThe last patch needs work. Anyone can pick this up I have some other priority work.
Comment #24
schnydszch commentedHi! I am also experiencing this. I'm on Drupal 8.9.11. Thanks in advance!
Comment #25
Yara Emmanuelle commentedHey there!
This patch also doesn't work for Conditional fields 4.0@alpha version.
Comment #26
Yara Emmanuelle commentedHey there!
This patch also doesn't work for Conditional fields 4.0.0-alpha1 version.
Comment #29
saurabh-2k17 commentedHi, attaching a working patch.
Comment #31
szhu commentedComment #32
saurabh-2k17 commentedThank you everyone for your efforts.