If the "Insert value from widget" is used at the dependency and the field is required, it isn't marked as "triggered" in some cases. I mostly saw it when using single checkbox.
$dependency_values = $context == 'view' ? $options['value'] : $options['value_form'];
For me, this will be a non-array in this case and then
return array_values($dependency_values) == array_values($values); this fails.
See my patch, here it solved my issues.

Comments

Gemma Morton’s picture

The above has been fixed in another issue, here:

However, there is still an exception here (as the code above does not resolve this).

In that, when you have said, "hide" the 2nd field, when the dependant has value of "none", then it doesnt register as triggered which prevents the #required from being set to TRUE

I made the following changes:

function conditional_fields_evaluate_dependency($context, $values, $options) {
       if (!is_array($dependency_values)) {
        .......
        // Special Use Case,
        // If the Condition is set to Invisible when value is "" (empty)
        // Then the check needs to be, is_triggered when != empty
        if (($options['condition'] == 'value') && ($options['value_form'] == '_none')) {
          return $dependency_values != $values;
        }

        return $dependency_values === $values;
      }

     // If we are in form context, we are almost done.
    if ($context == 'edit') {
      .....
      // Special Use Case,
      // If the Condition is set to Invisible when value is "" (empty)
      // Then the check needs to be, is_triggered when != empty
      if (($options['condition'] == 'value') && ($options['value_form'] == '_none')) {
        return array_values($options['value']) != array_values($values);
      }

      return array_values($dependency_values) == array_values($values);
    }

}

Patch attached.

socialnicheguru’s picture

git apply conditional_fields_insertvalue_required.patch
fatal: corrupt patch at line 30

kenorb’s picture

Issue summary: View changes
StatusFileSize
new1.49 KB
dqd’s picture

Status: Needs review » Closed (outdated)

Thanks for the report and all the efforts in here. But due to inactivity in this issue for some years and because of the upcoming EOL of Drupal 7, I will close this issue on the way by cleaning up the issue queue.

Feel free to re-open as "Needs review" if you found a solution or have a patch to be reported to help others on this outdated version.

If you think this issue or missing feature should be addressed in a newer Drupal core 8 and above compatible version of this project, then please file a new issue to the latest dev.