Support Forum
Support › Meta Box Conditional Logic › TypeError: logics is undefinedResolved
TypeError: 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';
Hi 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
I get the same error "TypeError: logics is undefined" when I use conditional logic in a field which is part of a group field.
Can you please post the code of your meta box?
Thanks 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' => '
',
],
*forgot to include it between code tags:
'placeholder' => '
',
again it strips out the characters. I will use spaces this time:
& # 1 0 ;
Can you post the code on pastebin.com? The forum auto strips all unwanted characters.
Just 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 to select_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]
.
Hi 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 "Meta Box 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,
Brian
Hi Brian,
Could you please share your code which uses conditional logic? I will check it on my end.
Hi 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.
P.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)
After 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 or when
conditions (as nothing in the docs said those are required attributes (I see the code adds those if missing).
Hi 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?