Conditional Logic broken
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- frontend
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.
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 ){
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
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.
More from AdvancedCustomFields/acf
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
AdvancedCustomFields/acf#1038 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AdvancedCustomFields/acf#1034 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
AdvancedCustomFields/acf#1032 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AdvancedCustomFields/acf#1029 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
AdvancedCustomFields/acf#1028 · 1 comment ·
All issues in AdvancedCustomFields/acf
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·