I noticed the dependency (at the visible state) is not maintained in the edit form. I mean if an option is selected in A field to make B field to be revealed (become visible) and the save button to clicked to create the node, when you return to edit that specific node the B field is not visible even though the A field remains selected (returns to how the form was when you want to create a new node).

This is not the expected behaviour, or is it? One would expect the validation will be attached to the form id and not to just the field id or class.

Update
=====
In my instance, A field is a radio button and B field is select list. The site is D8.8.5.

Comments

ojchris37 created an issue. See original summary.

ojchris’s picture

Issue summary: View changes
chucksimply’s picture

Yeah, this is a major bug. Same thing happening on my end. I have one select field managing the display of multiple different types of fields (textarea, photo, inline entity form). All are totally hidden when editing the node page even though the managing select field is selected.

chucksimply’s picture

Version: 8.x-1.0-alpha7 » 4.0.0-alpha1

Changing to latest version, as the bug still persists here.

hmendes’s picture

Version: 4.0.0-alpha1 » 4.x-dev

Hello!
I could only reproduce this error when using a select list field as trigger. Is this the same problem from #3168929: Display conditional form field not displayed when re-editing the node?

chucksimply’s picture

Same issue with radio buttons as select. Yes it does seem to duplicate your noted issue.

telegraph’s picture

Hi,
Originally reported this in the related issue (although marked fixed/closed, the problem persists). Issue is still present in latest 4.0.0-alpha1.

We are using the entity reference field to reference a taxonomy. On node edit, the term is still selected, but the related conditional fields are not showing. We have to unselect the term and re-select it for the fields to show (field data in dependent fields is preserved).

same issue as https://www.drupal.org/project/conditional_fields/issues/3168929

bunty badgujar’s picture

Hello,
I am also facing the same issue with multivalued select field as selector. Until this issue gets solved, we have used following alternative.

Calling change event manually on edit form. Please feel free to suggest better alternative.

Form alter

function HOOK_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $entity = $form_state->getFormObject()->getEntity();
  if ($entity instanceof NodeInterface) {
    // Attached conditional fix for only node edit form.
    if (!$entity->isNew()) {
      $bundle = $entity->bundle();
      $entity_type = $entity->getEntityTypeId();
      $dependencies = conditional_fields_load_dependencies($entity_type, $bundle);
      if (!empty($dependencies) && !empty($dependencies['dependees'])) {
        foreach (array_keys($dependencies['dependees']) as $dependee) {
          // Add custom class to dependee field. So that we can call change event in custom js.
          $form[$dependee]['#attributes']['class'][] = 'conditional_field_custom_event';
          // Attached library is not already atatched.
          if (!in_array('custom_module/custom_module.conditional_fields_fix', $form['#attached']['library'])) {
            $form['#attached']['library'][] = 'custom_module/custom_module.conditional_fields_fix';
          }
        }
      }
    }
  }
}

Js code

(function ($, Drupal, drupalSettings) {
  Drupal.behaviors.custom_module = {
    attach: function (context, settings) {
      Drupal.behaviors.custom_module.recallChangeEvent(context);
    },

    /**
     * Recall change event for dependee field.
     *
     * @param context
     */
    recallChangeEvent: function (context) {
      $('.conditional_field_custom_event', context).each(function(index, element) {
        var selectorId = $(element).attr('id').replace('-wrapper', '');
        $(`#${selectorId}`).trigger('change');
      });
    },
  };
})(jQuery, Drupal, drupalSettings);
darkodev’s picture

Tried all patches for core and conditional_fields for D10, but nothing worked.

Thanks to workaround in #8. Works flawlessly for multi-select dependee fields when loading the node edit form.

Just one note that dependencies are now loaded through a service, like so:

$dependencies = \Drupal::service('conditional_fields.element_alter_helper')->loadDependencies($entity_type, $bundle);