AdvancedCustomFields / AdvancedCustomFields/acf
Conditional Logic broken
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
As explained in the support ticket #1619769049, conditional logic has broken either in a WP upgrade between 5.5.5 and 5.8 or an ACF upgrade between 5.9.6 and 5.9.9.
The HasValue condition does no longer work on multi-select user field. The work-around using a LessThan rule does not work on cloned fields.
The reason for the first error is, that an empty Array is considered to be a non-empty value.
The reason for the second error is that isLessThan() consideres null to be not-less-than-one
Both can be fixed with the following patch:
Index: assets/build/js/acf-input.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/assets/build/js/acf-input.js b/assets/build/js/acf-input.js
--- a/assets/build/js/acf-input.js (revision 8fd2564c86de244ca0b88c7773e0a861d7044cc5)
+++ b/assets/build/js/acf-input.js (date 1630616522694)
@@ -5289,7 +5289,11 @@
label: __('Has any value'),
fieldTypes: [ 'text', 'textarea', 'number', 'range', 'email', 'url', 'password', 'image', 'file', 'wysiwyg', 'oembed', 'select', 'checkbox', 'radio', 'button_group', 'link', 'post_object', 'page_link', 'relationship', 'taxonomy', 'user', 'google_map', 'date_picker', 'date_time_picker', 'time_picker', 'color_picker' ],
match: function( rule, field ){
- return (field.val() ? true : false);
+ var val = field.val();
+ if( val instanceof Array ) {
+ val = val.length;
+ }
+ return (val ? true : false);
},
choices: function( fieldObject ){
return '<input type="text" disabled="" />';
@@ -5625,6 +5629,9 @@
if( val instanceof Array ) {
val = val.length;
}
+ if( val === undefined || val === null || val === false ) {
+ return true;
+ }
return isLessThan( val, rule.value );
},
choices: function( fieldObject ){
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in assets/build/js/acf-input.js at the HasValue and LessThan conditional logic handlers. Reproduce the reported cases with a multi-select user field and a cloned field, then verify that empty arrays and null, undefined, or false values are handled as described. Done means both conditional logic cases work without the reported workarounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100