Utilizing the Client-side hierarchical select module in conjunction with the Conditional Fields module doesn't work in its current state. The form states do not recognize the values in the CSHS element/widget.

Issue fork cshs-3150700

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kerasai created an issue. See original summary.

kerasai’s picture

Status: Active » Needs review
StatusFileSize
new915 bytes

Attached is a patch that adds a ConditionalFieldsHandler plugin to allow conditional fields to properly apply states to the element/widget.

kerasai’s picture

StatusFileSize
new1.49 KB
new613 bytes

Uploaded a new patch to address an issue with applying the states on initial form load. For whatever reason the states were being ignored when loading the form under conditions where states should hide/disable/etc.

I'm not in love with the solution, but it changes the original element's value and resets it as the jQuery plugin is applied in order to trigger the initial states handling.

heikkiy’s picture

It seems like the latest patch is not compatible with the recommended version 3.4.

kerasai’s picture

@HeikkiY, that is probably correct. This change applies to the1.x branch, I'm currently running 8.x-1.7.

kerasai’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev
StatusFileSize
new915 bytes

Re-rolled for 3.x version.

This change is only the conditional fields plugin. The wonky JS is no longer needed.

heikkiy’s picture

I tested this with the latest 4.0.0 release. Patch applies cleanly the field formatter seems to work fine.

heikkiy’s picture

Status: Needs review » Reviewed & tested by the community
mayela’s picture

I tested patch #3 with Drupal 10.1.4 and cshs 4.0 and I am getting this error:

AssertionError: assert(!\array_key_exists($element['#none_value'], $element['#options'])) in assert() (line 64 of modules/contrib/cshs/src/Element/CshsElement.php)

I get the error when I try to add a condition between two fields , field 1: Document Type ( cshs ) and Field 2: Lab Document Type ( Select list )
The condition I am trying to set is that if field 1 has the value of option: Laboratories , show Lab Document Type field

mayela’s picture

I was able to fix the assertion error by checking if the key specified by $element['#none_value'] exists in the array $element['#options']. If it doesn't exist, the code inside the if block will be executed.

Added this to line 64 to cshs/src/Element/CshsElement.php file

if (!array_key_exists($element['#none_value'], $element['#options'])) {
     // Make sure the `#none_value` doesn't overlap with other keys.
     \assert(!\array_key_exists($element['#none_value'], $element['#options']));
     // Make sure the `_none` option is added very at the beginning of a list.
} 
sarathkm’s picture

Version: 8.x-3.x-dev » 4.0.x-dev
Status: Reviewed & tested by the community » Needs work

Facing issue with AssertionError: assert(!\array_key_exists($element['#none_value'], $element['#options'])) in assert() (line 64 of /var/www/html/web/modules/contrib/cshs/src/Element/CshsElement.php)

sarathkm’s picture

Assigned: Unassigned » sarathkm

sarathkm’s picture

Status: Needs work » Needs review

Fixes AssertError for Conditional Field

sarathkm’s picture

Assigned: sarathkm » Unassigned
sarathkm’s picture

StatusFileSize
new2.46 KB

sarathkm’s picture

StatusFileSize
new1.93 KB
danharper’s picture

I'm facing this issue using the field_states_ui module.

The showing and hiding just doesn't seem to work even with the latest patch.

joseph.olstad’s picture

@danharper, you'll want to rebuild cache after applying any patch.

  • joseph.olstad committed c56e63aa on 4.0.x
    Issue #3150700 by sarathkm, kerasai, HeikkiY, mayela: Conditional Fields...
joseph.olstad’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

sarathkm’s picture

Hi @joseph.olstad,

I am not sure why, but I don't see this Issue credit being added to any of the contributor.

joseph.olstad’s picture

Hi, for some reason d.o removed the author suggestion from the issues.

With that said, multiple contributors are being credited, including sarathkm see below:
Issue #3150700 by sarathkm, kerasai, HeikkiY, mayela: Conditional Fields Integration