The visibility condition is not working on the profile form attached to the user registration form. This is using the Profile module.

1) Create a profile type "User Profile".
2) Add a checkbox to the "User Profile".
3) Add a Text(Plain) field to the "User Profile".
4) Set the Profile form to appear on the Registration form.
5) Add a checkbox to the "User Account".
6) Add a Text(Plain) field to the "User Account".
7) Create a dependency that makes each text field visible if the associated checkbox is checked.
8) try to create a new account and test each checkbox/text field dependency.

You will see that the one on the user account works but the one on the profile does not work.

Comments

CompBoy22 created an issue. See original summary.

imclean’s picture

Conditional fields doesn't seem to work with Profile module at all. To check, create a new profile type and add fields. There is no "Manage Dependencies" tab within the profile settings.

imclean’s picture

It looks like you can get to Profile dependencies another way: /admin/structure/conditional_fields/profile/profile_name

I'm still having trouble getting conditionals to work with Profile. I'm trying a simple show/hide conditional with a select list as the controlling field but it's having no effect on the form.

imclean’s picture

My problem appears to be with Commerce and embedding the profile form within billing. An issue related to Inline Entity Form may resolve this issue as well: #2856720: Support for Inline Entity Form

7thkey’s picture

I'm having the same issue as #3, conditional fields module doesn't work with profile.

hanness’s picture

confirming #3

  • setting conditions at /admin/structure/conditional_fields/profile/profile_name works fine
  • if creating an user with profile, the conditions does not apply
  • if editing the profile after creating, the user the conditions does apply
nanabrownee’s picture

Any solution for this?

Andrew.Dmytriv’s picture

This patch works for the profile on the registration page and for commerce profile customer billing-information.

socialnicheguru’s picture

Status: Active » Needs review
kris77’s picture

This patch cannot be applied to the last dev version

Andrew.Dmytriv’s picture

I added the new patch for the latest dev version

Andrew.Dmytriv’s picture

dwkitchen’s picture

+++ b/conditional_fields.module
@@ -181,11 +181,37 @@ function conditional_fields_element_after_build($element, FormStateInterface &$f
+    if ($first_parent == 'billing_information') {

What's the reason we need to make reference to Commerce Billing Profile?

Tested and working with custom profiles on user registration form.

dwkitchen’s picture

Version: 8.x-1.0-alpha2 » 8.x-1.x-dev
Status: Needs review » Needs work

Well, I said it works...

It correctly controls the fields to show on the registration form; but it breaks the submission of the form, preventing user registration.

sevenfish’s picture

My profile's id is "license_information_profiles". Because I have two underscore(_), the #12 patch is not working. WHen I change one line in “conditional_fields.module”. It is working now.

Old:

+ list($bundle, $entity_type) = explode('_', $first_parent);

New:

+ $bundle = preg_replace('/_profiles$/', '', $first_parent);
dwkitchen’s picture

Status: Needs work » Needs review
sevenfish’s picture

After I submit to “Create ew account” in Register Form, it always shows error. I check log.

Error: Call to a member function extractFormValues() on null in Drupal\Core\Entity\ContentEntityForm->copyFormValuesToEntity() (line 338 of xxxxxxxxx\web\core\lib\Drupal\Core\Entity\ContentEntityForm.php)

Google and find this post. It writes:

if (!$form_state->has('entity_form_initialized')) {
  $this->init($form_state);
}

I check $form_state. After I use $form_state->setStorage($array), the "entity_form_initialized" in "storage" property is gone. So I edit it.

Old :

      $form_state->setStorage(['profile_entity' => [
        'bundle' => $bundle,
        'entity_type' => $entity_type,
      ]]);

New :

      $form_state->setStorage(array_merge($form_state->getStorage(), ['profile_entity' => [
        'bundle' => $bundle,
        'entity_type' => $entity_type,
      ]]));

Pass it.

Last issue. After I hide "required" field. It is still required.

j-vee’s picture

Version: 8.x-1.x-dev » 4.x-dev
StatusFileSize
new7.85 KB

Re-created the patch for 4.x with additional fixes.

The code assumes right now that there's the word "profile" in the profile name. This could probably be streamlined if there's some code that first fetches all machine names of profiles and compares against them in conditional_fields_element_after_build function. But for our purposes, this works great.

j-vee’s picture

Sorry, here's the latest one that works. Added the fix by sevenfish above.

daften’s picture

I'm testing out this patch, and the latest version doesn't work, and I don't see how it can work. The references from the user object to the profiles is _profiles. Where the regex with ^entity comes from, I have no idea, but maybe you can clarify how you got to that point @j-vee? :)

Using the patch as-is doesn't work for me, but replacing it by checking for _profiles$ doesn't work either and produces this error:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\conditional_fields\ConditionalFieldsFormHelper::elementAddProperty() must be of the type array, null given, called in /var/www/html/web/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php on line 177 in Drupal\conditional_fields\ConditionalFieldsFormHelper->elementAddProperty() (line 862 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).
zegmant’s picture

It still does not work on profiles.
Module 4.0.0-alpha2
Drupal 9.5.3
No patches of this page cannot be applied because of .module file changes

chucksimply’s picture

Status: Needs review » Needs work
nitrocad’s picture

Use ECA and ECA forms module instead of Conditional Fields.

  • ECA event: Build form (form_id)
  • Eca action: Form field: add state
freelylw’s picture

any progress for this issue, conditional fields doesn't work on profile module in Drupal10.x, I am getting the same problem