When a Paragraphs field is used as the dependency (target field), conditionals have no effect. I've tried various combinations of settings on the conditional, and nothing seems to affect the dependent Paragraph field.

To reproduce:

  1. Install Conditional Fields and Paragraphs modules
  2. Create a simple paragraph type (e.g. simple text, with a long text field)
  3. From a content type, add a Paragraphs reference field to be the dependency and a boolean field to be used as the dependee
  4. Create a conditional to show the Paragraphs field when the Boolean is checked
  5. Create content using this content type. The paragraphs field will still be visible, and the trigger field will have no effect

Comments

mmcdermott created an issue. See original summary.

efrainh’s picture

Status: Active » Closed (duplicate)

Hi, thank you for reporting this but the same issue was already reported here: https://www.drupal.org/node/2530770

megan_m’s picture

I don't believe it is the same issue, or maybe the solution is the same (?).

This is issue is describing conditional field directly on a node, affecting a paragraphs reference field on that node. If I understand the other issue correctly, the conditionals are within the paragraph bundle, and they do work the first time. In this case they don't work at all.

garek007’s picture

HI I experienced this issue recently as well. Is there an easy way I can fix this myself?

labboy0276’s picture

Status: Closed (duplicate) » Active

The issue you linked to is not the same issue. I am reopening this as this does need to be addressed. The issue you linked to is for cardinality issues within paragraphs and conditional fields.

Conditional Fields 8.x just does not work with paragraphs. I have a similar situation where I tried to hide a paragraph field with a select list on load of the node edit page. it does not work, it does not hide it.

devil2005’s picture

I confirm this issue (drupal 8.3.2 and paragraphs 8.x-1.1)

Thanks

piggito’s picture

Hi, I think we need more details about the failing cases. I have just tested dev version with drupal 8.3.2 and paragraph 8.x-1.1 and it worked for me.
In my case I used a paragraph with 2 date fields as the target, a boolean field as the controller field and the condition was to make it invisible when the boolean field is checked.
Maybe it is related to some specific behavior in the target field.

megan_m’s picture

Yes, this is working for me too now, following the above instructions.

I am getting this error when I create the conditional:

Notice: Undefined offset: 0 in Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm() (line 326 of modules/contrib/conditional_fields/src/Form/ConditionalFieldEditForm.php).
Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm(Array, Object)

But that's probably a different problem.

labboy0276’s picture

piggito, I am using a select list but the rest is similar to your setup.

labboy0276’s picture

I just updated everything and tested again, still doesn't work. In fact conditional fields isn't working with a select list at all. I will open a separate issue for that.

semisem’s picture

I am having the same issue too. Added a paragraph field as target, another paragraph field is the control field conditional field dependency does not work at all.

yuanyuan.zhang’s picture

Yes I am having the same issue. I have a paragraph field with regular text and another paragraph field with media bundle, both controlled by a text list, and neither of them works.

piggito’s picture

StatusFileSize
new18.68 KB
new12.23 KB
new11.49 KB
new48.38 KB
new35.9 KB
new9.59 KB
new21.06 KB
new21.21 KB
new36 KB

Hi,
I have tested again with Drupal core 8.3.3, Paragraphs 1.1 and Conditional Fields dev version and still couldn't reproduce the issue. I'm adding some screenshots of my test and maybe it could help if we get some screenshots of the missing cases to find a pattern.

  1. I created a Paragraph with Number Field Paragraph Number Field
  2. Then a 2nd Paragraph with Text Field Paragraph Text Field
  3. Now CT Test with a Text List field and the 2 previous Paragraphs CT Test fields
  4. There were 2 conditions:
    Conditions
    to show Paragraph with Number Field when Text List value is "value 1"
    Conditions Paragraph Number
    and to show Paragraph with Text Field when value is "value 2"
    Conditions Paragraph Text
  5. Finally, testing the node Test form
    No value selected
    value 1 selected
    value 2 selected

So as you see it seems to be working fine.

sashken2’s picture

Create field "field_list_text" in 1st or 2nd Paragraph and try again

OlgaRabodzei’s picture

Status: Active » Closed (cannot reproduce)

Hello everyone!

I checked once more with steps to reproduce in the description of this issue and can't reproduce the bug. Is it actual?
Could someone provide new STP or better a javascript test (tutorial)?

Regards Olga.

schackattack’s picture

Drupal 8.3.3 + Conditional FIelds 8.x-1.0-alpha2 and Paragraphs 8.x-1.1 doesn't work.

scott_euser’s picture

Status: Closed (cannot reproduce) » Needs review
StatusFileSize
new876 bytes

I can confirm, this is an issue with the 'Entity reference revisions' widget used in combination with Paragraphs.

The paragraph widget in this case is wrapped in a container and the container does not have a title. Without a title, the after build callback assumes conditional fields doesn't apply:

if (!isset($element['#title']) && !isset($element['widget']['#title'])) {
  return $element;
}

This solves it:

  // No widget title, maybe skip the conditional checks.
  if (!isset($element['#title']) && !isset($element['widget']['#title'])) {

    // For compatibility with field types that wrap themselves in containers
    // such as Paragraph reference fields, the widget title may be empty yet
    // still a valid candidate.
    if (isset($element['#type']) && $element['#type'] != 'container') {
      return $element;
    }
  }

Patch attached.

labboy0276’s picture

Status: Needs review » Reviewed & tested by the community

Thank You, this works for paragraphs that haven't been triggered yet.

mikemadison’s picture

the good news is that the patch applies cleanly and conditional fields is now working with paragraph fields. the bad news is that when i submit the conditional fields form to add new rules for conditional fields, i get a PHP warning because of an undefined offset. It's unclear to me if this is directly related to this work or not? We could certainly fix the issue with a simple isset check prior to the other code in the submitForm method.

Notice: Undefined offset: 0 in Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm() (line 316 of modules/contrib/conditional_fields/src/Form/ConditionalFieldEditForm.php).
Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('conditional_field_edit_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 576)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 44)
Drupal\services\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Benjoun’s picture

Is this patch will help with this related issue https://www.drupal.org/node/2902164 ?

Unfortunately, though it has been posted 3 month ago and we are a few to face the problem, no developpers have given any answer.

colan’s picture

colan’s picture

Title: Conditionals don't work on Paragraphs fields » Conditionals don't work on dependent Paragraphs fields
colan’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

#20: It's related, but not the same issue. See the description over there; it will explain the difference.

#17 no longer applies. Is this still a problem with the latest dev branch the just-released alpha3? That section of the code was rewritten recently.

colan’s picture

Issue tags: +Paragraphs
slydevil’s picture

I have just run into this issue with Drupal 8.4.4 and conditional fields 8.x-1.0-alpha4. Looks like the last commit is the alpha4 release. I'll see if I can get to the root of the issue and come up with a patch.

slydevil’s picture

Status: Postponed (maintainer needs more info) » Active
slydevil’s picture

Status: Active » Postponed (maintainer needs more info)

Sorry, my issue is actually #2902164, reverting.

colan’s picture

Status: Postponed (maintainer needs more info) » Postponed

This should probably wait for #1161314: Add basic Field Group support for ANDing conditions. Lots of refactoring (for general type of groups) going on there.

colan’s picture

Status: Postponed » Fixed

Actually, marking fixed as nobody's confirmed that this is still broken in over 2 years.

Status: Fixed » Closed (fixed)

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

tanmayk’s picture

Created simple paragraph type & 2 fields (select list & text field). Added condition to show/hide text field based on the value of a select list. The text field is always visible. No error in console or Drupal logs. It is still broken in 1.0-alpha10.

Drupal: 8.9.13
Conditional Fields: 1.0-alpha10
Paragraphs: 1.12

The combination of paragraphs & conditional_fields is very useful & should be working as expected. Please point to the correct the issue if I am updating the wrong one.

dqd’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

The combination of paragraphs & conditional_fields is very useful & should be working as expected.

"Should" and "expected" are complicated terms in connection with community driven projects. Consider this phrasing a little bit unfortunate choice.

Please point to the correct the issue if I am updating the wrong one.

As you stated you tested on 1.0-alpha10 but this issue is for 8.x-1.x-dev - so please test the proper branch and report back if it is still not working. Thanks for understanding and any help is appreciated.

justinchev’s picture

This is something I'm also experiencing. Conditional fields work fine within a regular node, but the exact same type of managed field conditions don't work within 'Paragraphs'.

I'm using the following versions:

  • Drupal core: 10.4.6
  • Conditional Fields: 4.0.0-alpha6
  • Paragraphs: 8.x-1.19

Steps to reproduce are similar to what others have said:

  1. Create a paragraph type.
  2. Add two fields to the paragraph type, eg. Boolean (yes/no) checkbox and a text field.
  3. Set up a conditional field via 'Manage dependencies' so that the text field (target) is either visible/hidden depending on whether the checkbox is checked/unchecked (controller).
  4. Create a node and add the paragraph type that you created.
  5. In the paragraph modal popup you will see the two fields, but the text field always shows no matter if the checkbox is checked/unchecked.

When selecting the checkbox I don't see any changes happening in the html, eg 'css display none' being applied as it does when using a regular node content type.

I'm using the 'Gin Admin' theme, but tried switching back to 'Claro' but that didn't make a difference.