[5.4] Fix: Showon fails open when source field does not exist (hidden by default instead) #46488
+6
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue in Joomla’s showon implementation where dependent fields are always shown, even when the referenced source field does not exist in the DOM.
This “fail-open” behaviour can lead to incorrect form states, invalid UI logic, and unintended visibility of fields.
Problem
Currently, if a field contains something like:
showon="nonexistent_field:1"and nonexistent_field is not present in the form:
This is counter-intuitive and causes issues especially in:
This behaviour is likely an oversight rather than an intentional feature.
Expected Behaviour
If the source field defined in showon does not exist, then the condition cannot be fulfilled, therefore the dependent field should be hidden by default.
Solution
This PR adds a simple and safe check in Showon (build/media_source/system/js/showon.es6.js):
After collecting all origin fields for a given showon condition:
if origin.length === 0,
→ the dependent field is immediately hidden,
→ and the joomla:showon-hide event is fired.
This changes the behaviour to Fail closed instead of fail open
(a missing condition hides a field rather than incorrectly showing it)
The fix does not modify the data structure, PHP FormHelper logic, or any API and is fully backward compatible unless someone relied on the previous incorrect behaviour (unlikely).
How to Test
Please test both Custom Fields and standard XML JForm definitions.
1. Test Using Custom Fields
A) Prepare the fields
Go to:
Content → Fields
Create a field:
Field A:
Type: List
Name: controller
Options: Yes=1, No=0
Create another field:
Field B:
Type: Text
Name: dependent
Showon:
controller:1B) Test the normal behaviour
Edit an article.
Set “Controller” to "Yes" → Field B should appear.
Set “Controller” to "No" → Field B should hide.
C) Test the missing-source behaviour
Unpublish or Delete Field A (the controller field)
Open the article again.
Expected result after applying the PR:
“Dependent” field is hidden by default
No JS errors occur
Switching values of other fields does not accidentally reveal it
Current behaviour (before PR):
Field B is incorrectly visible.
2. Test Using XML Form Definitions
A) Create a simple XML form (administrator or component)
Example snippet:
<field name="dependent" type="text" label="Dependent Field" showon="nonexistent:1" />B) Load the form in the backend (module, component, plugin etc.)
Expected result after PR:
The “dependent” field is hidden because the source field does not exist.
Current behaviour:
The field is incorrectly shown.
showon="controller:1[AND]nonexistent:2"Expected after PR:
Even if controller exists, the missing nonexistent should invalidate the entire condition, hiding the field.
Backward Compatibility
This change should not break valid configurations.
The only difference occurs when showon references a field that:
does not exist,
was renamed,
was deleted,
or is dynamically removed in subforms.
In these cases the new behaviour is more correct and prevents accidental visibility.
This PR makes the showon behaviour more predictable, safer, and consistent by hiding dependent fields when the source field is missing — a long-standing edge case that often leads to incorrect UI states.