Skip to content

Fix - Visibility conditions not working on tree cascade dropdown questions#30

Open
RomainLvr wants to merge 2 commits into
mainfrom
fix/tree-cascade-dropdown-visibility-conditions
Open

Fix - Visibility conditions not working on tree cascade dropdown questions#30
RomainLvr wants to merge 2 commits into
mainfrom
fix/tree-cascade-dropdown-visibility-conditions

Conversation

@RomainLvr

Copy link
Copy Markdown

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !44659
  • Here is a brief description of what this PR does

ItemAsTextConditionHandler uses getName() which returns only the item's own name. For tree dropdowns, a child item's name does not include its ancestors, so a condition like "contains Parent" always failed. Fixed by introducing TreeCascadeItemAsTextConditionHandler in the plugin, which uses completename ("Parent > Child") for CommonTreeDropdown items. TreeCascadeDropdownQuestion::getConditionHandlers() is overridden to substitute this handler.

@RomainLvr RomainLvr requested a review from stonebuzz June 17, 2026 12:19
@RomainLvr RomainLvr self-assigned this Jun 17, 2026
@RomainLvr

Copy link
Copy Markdown
Author

I have the customer test it

@stonebuzz stonebuzz requested a review from ccailly June 24, 2026 15:28
Comment on lines +101 to +106
if ($item instanceof CommonTreeDropdown) {
$completename = $item->fields['completename'];
$text = is_string($completename) ? $completename : '';
} else {
$text = $item->getName();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else branch ($text = $item->getName()) is dead code. This class is only ever constructed in TreeCascadeDropdownQuestion::getConditionHandlers(), which itself is only reachable for CommonTreeDropdown itemtypes

Suggested change
if ($item instanceof CommonTreeDropdown) {
$completename = $item->fields['completename'];
$text = is_string($completename) ? $completename : '';
} else {
$text = $item->getName();
}
// Use completename for tree dropdowns so that conditions referencing
// ancestor nodes match correctly (e.g. "contains Parent" matches a child
// whose completename is "Parent > Child").
$completename = $item->fields['completename'] ?? '';
$text = is_string($completename) ? $completename : '';

* Verify that CONTAINS evaluates to true when the searched text appears in
* the completename of the selected item but not in its own name alone.
*/
public function testContainsMatchesCompletename(): void

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case where the parent item itself is selected (not a child), confirming that CONTAINS 'Parent Location' still matches when completename = 'Parent Location'? The two existing tests only cover a child item; the root-level selection path is untested.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case where no item is selected (items_id = 0)? applyValueOperator returns false for both operators in that case, which means a NOT_CONTAINS X condition evaluates to false (dependent question hidden) when nothing is selected. This is non-obvious behavior and worth pinning with a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants