TypeError: logics is undefined
Support › MB Conditional Logic › TypeError: logics is undefinedResolved
- This topic has 21 replies, 6 voices, and was last updated 5 years ago by
Anh Tran.
-
AuthorPosts
-
March 7, 2020 at 2:03 AM #18497
Austin Passy
ParticipantTypeError: logics is undefinedconditional-logic.js:221:18
You should check for the logics object before sub checks, like:
var relation = typeof logics !== 'undefined' && typeof logics.relation !== 'undefined' ? logics.relation.toLowerCase() : 'and', success = relation === 'and';
March 9, 2020 at 5:21 PM #18512Anh Tran
KeymasterHi Austin,
Thanks for your feedback. I guess, it's a sign that there's a problem with the logic syntax. Can you please check it first? And if possible, please send me the code for meta boxes, so I can double check.
Thanks
March 18, 2020 at 2:51 PM #18570woorise
ParticipantI get the same error "TypeError: logics is undefined" when I use conditional logic in a field which is part of a group field.
March 18, 2020 at 4:00 PM #18576Anh Tran
KeymasterCan you please post the code of your meta box?
March 18, 2020 at 4:30 PM #18577woorise
ParticipantThanks for the quick respond Anh. In my case I found that the issue occurs when I include the following characters as a placeholder in the field I want to hide: " "
Here is the part of the code:
[
'name' => esc_html__( 'Field', 'test' ),
'id' => 'field',
'type' => 'textarea',
'visible' => [ 'test_field', '!=', '' ],
'placeholder' => ' ',
],March 18, 2020 at 4:34 PM #18578woorise
Participant*forgot to include it between code tags:
'placeholder' => ' ',
March 18, 2020 at 4:36 PM #18579woorise
Participantagain it strips out the characters. I will use spaces this time:
& # 1 0 ;
March 20, 2020 at 2:59 PM #18597Anh Tran
KeymasterCan you post the code on pastebin.com? The forum auto strips all unwanted characters.
April 25, 2020 at 12:28 AM #19282Austin Passy
ParticipantJust getting around finally to looking into this issue further now.
I've tracked it down to an issue on a
taxonomy
type field with field_type set toselect_advanced
.Current condition:
'visible' => [ 'tax_input[promo_type]', 'contains', 16, ]
Also tried to different syntax's like
[slug:tax_input[promo_type], 'contains', 'term-slug']
,[slug:tax_input[promo_type], '=', 'term-slug']
,[tax_input[promo_type], '=', 16]
.April 27, 2020 at 1:38 AM #19295Brian
ParticipantHi Anh,
I'm getting the same error. Did you all find a solution? I can't figure out why the conditional logic isn't adding in the style="display:none;" or "display:block;" to show/hide fields?I created everything in a different site which has the "MB Builder" plugin activated and the conditional logic works on that site. But as soon as I copy the exact code to a different site and install the required "conditional logic" plugin. It does not work. I've tried to find what would be different between sites and can't find much?
What am I missing here?
Thanks,
BrianApril 27, 2020 at 9:24 AM #19301Long Nguyen
ModeratorHi Brian,
Could you please share your code which uses conditional logic? I will check it on my end.
April 28, 2020 at 5:06 AM #19317Aart Jan van der Linden
ParticipantHi all,
same here. The code used to work fine, a few weeks ago.
Quite normal setup, but in some cases this 'logics is undefined' error appears, making it impossible to use the controls.April 28, 2020 at 5:18 AM #19318Aart Jan van der Linden
ParticipantP.S. this is the error thrown:
conditional-logic.js?ver=1.5:221 Uncaught TypeError: Cannot read property 'relation' of undefined at isLogicCorrect (conditional-logic.js?ver=1.5:221) at HTMLScriptElement.<anonymous> (conditional-logic.js?ver=1.5:182) at Function.each (jquery.js?ver=1.12.4-wp:2) at jQuery.fn.init.each (jquery.js?ver=1.12.4-wp:2) at runConditionalLogic (conditional-logic.js?ver=1.5:177) at conditional-logic.js?ver=1.5:595 at dispatch (jquery.js?ver=1.12.4-wp:3) at r.handle (jquery.js?ver=1.12.4-wp:3)
April 28, 2020 at 6:21 AM #19319Austin Passy
ParticipantAfter spending many hours testing and checking all conditions the only logical issue comes down to the updated conditional-logic.js. If I go in an edit the following two functions, everything works again:
isLogicCorrect()
&getWatchedElements()
In
isLogicCorrect()
check logics before continuing since :if (typeof logics === 'undefined') { return; }
In
getWatchedElements()
wrap logic.when.forEach:if (typeof logic !== 'undefined') { logic.when.forEach(addWatchedElement, this); }
We have a lot of conditions there are simple and do not have
relation
definitions orwhen
conditions (as nothing in the docs said those are required attributes (I see the code adds those if missing).April 28, 2020 at 2:15 PM #19330Anh Tran
KeymasterHi Brian, Aart and Austin,
I've debugged with your code and still can't reproduce the error. Although I can add code as Austin suggested, but am not sure the root cause. I also tried Aart's code above, and Austin case with taxonomy and still see nothing.
Can you guys provide me a full code that shows the error?
-
AuthorPosts
- You must be logged in to reply to this topic.