Problem/Motivation

I have an conditional field that appears when user selects a value of another field.
When the node is saved and re-edited, the conditional field is not displayed - the user needs to select the corresponding value of the other field "again". Is this a misconfiguration of my fields or does this module not support this scenario?

Steps to reproduce

  • Create a conditional field
  • Select the trigger value in another field
  • Enter the value in the conditional field
  • Save node
  • Re-Edit node
  • The entered value in the conditional field is not visible (also it is in it)

Proposed resolution

Perhaps a misconfiguration?

Comments

inna_rist created an issue. See original summary.

opi’s picture

Same here ; My first field (aka the trigger) is a select field handled by Chosen, you too ?

larisse’s picture

Hello! I was unable to reproduce this error. Could you test in the dev version of this module, because I think that probably this error is fixed.

telegraph’s picture

Facing the same issue, when editing a node, the dependent (target) fields are hidden until the control field is re-filled.
Control field has 'insert value from widget' for input mode, the control field is an entity reference select list based on a taxonomy .
Have version: 8.x-1.0-alpha10 installed and also tested the dev version without success.

hmendes’s picture

Hello!
I was unable to reproduce this error, could you help me @telegraph @opi @inna_rist?
These were the steps i followed:

  • Got a new Drupal 9.1.6 environment and set it up with Lando
  • Downloaded Conditional_field version 8.x-1.x-dev with composer and installed the module
  • Created a conditional field to 'Article' contents
    • Target field -> field_image
    • Controlled by -> Title
    • Description -> Visible
    • Condition -> Value
    • Values input mode -> Insert value from widget
    • Title value -> 'test'
  • Created a Article content
  • Title = 'test' (image field is shown)
  • Entered a image on the field with its 'Alternative text'
  • Saved the content
  • Clicked on Edit
  • The Title field is with 'test' and the image field is showing the image and text I entered before
gocaps’s picture

I did some testing on 8.x-1.x-dev, and can confirm that the bug exists when the dependency is controlled by an Entity Reference field, as mentioned by @telegraph in #4.

I was able to reproduce @hmendes test in #5 also, which further confirms the issue with Entity Reference fields.

hmendes’s picture

Assigned: Unassigned » hmendes

I'm trying to work on this issue, but just for the record:
The problem doesn't seems to be with the Entity Reference fields, but with the select field:

If we have a text or number select field without the value "0", it will work normally. However, if the control value is the value "0", it doesn't work.
The problem with the Entity Reference field, is that it puts the first value in the list as the value "0" (if we put the second value of the list as the control value, the conditional field works normally), but it is not happening to all Reference fields... I'm still trying to figure out what is the problem exactly.

Steps:

  • Target field: anything
  • Controlled by: Entity Reference Field as select field, or any select list field containing the value "0"
  • Values input mode: insert values from widget
  • Value:
    • the first position, if it is a Entity Reference Field
    • the position that contains the value "0" (eg. you have a list: 1,3,0,5,2 -> select the "0")
chucksimply’s picture

I can confirm this issue as well. Though it occurs for me on both select and radio widgets... entity reference fields (referencing taxonomy in my case).

hmendes’s picture

Version: 8.x-1.0-alpha9 » 4.x-dev
Component: Miscellaneous » Code
Category: Support request » Bug report
Status: Active » Needs review
StatusFileSize
new676 bytes

Here's the patch to fix the problem.
Please review.

hmendes’s picture

Assigned: hmendes » Unassigned
chucksimply’s picture

Unfortunately, the patch did not work for me. For both Radio and Select options. Using 4.0.0-alpha.

hmendes’s picture

Hello @ChuckSimply, could you provide the steps to reproduce your issue, please?

chucksimply’s picture

Here's my setup...

1) A taxonomy entity reference Conditional Field, controlling multiple other fields on a node form.
2) Go to a node/add form.
3) Select the conditional field value (via select or radio widget).
4) Dependent fields show up as expected, depending on the conditional field's value.
5) Save node form
Edit - Issue Area...
6) Edit the same node just saved.
7) Conditional field value shows, but all dependent fields hidden.
*Note - One of my conditional fields values DOES show some fields on edit. The fields that show are Number and all fields within a Field Group. Others are hidden. (it worked this way before the patch, so the patch had no effect on this)
8) Selecting a different Conditional field value, then back to the same value... shows the previously hidden fields.

Thanks again for looking into this!

hmendes’s picture

I'm going to take a closer look at this, but just one thing:

I tested this issue with the "Values input mode" as "Insert value from widget", the others input mode under "Set of values" are having problem when the value is "0" ( it affects the entity reference fields as well because the value for the first option of the select/radio is "0"). So if you are creating a conditional field with a select/radio field, and selecting the first option as the trigger value, and the input mode is "All of these values (AND)", or any option under "Set of Values". it will not work with this patch only.

I've created the issue #3221537: Values input mode with Set of Values not working with "0", but it still needs work as it didn't pass the tests. (didn't tried to solve both issues here because the #3221537: Values input mode with Set of Values not working with "0" is not happening only with select/radio fields).

chucksimply’s picture

Ah gotcha. Yeah the two fields I mention that ARE showing on the node edit form are using "Insert value from widget." The ones not working are "Values input mode." So this makes sense.

I'll give your patch on the referenced issue a try (even though it failed) and report back over there.

laisbonafe’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.97 MB
new3.84 MB

Hi, I tested the patch of comment #9, the patch fixed the issue,
I add 2 videos the test process, before patch and after patch.

thalles’s picture

Looks good to me!
Thanks @all!

thalles’s picture

Status: Reviewed & tested by the community » Fixed

  • thalles committed 011886f on 4.x
    Issue #3168929 by hmendes, laisbonafe, thalles: Display conditional form...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.