TypeError: logics is undefined

Support MB Conditional Logic TypeError: logics is undefinedResolved

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #18497
    Austin PassyAustin Passy
    Participant

    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';
    #18512
    Anh TranAnh Tran
    Keymaster

    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

    #18570
    woorisewoorise
    Participant

    I get the same error "TypeError: logics is undefined" when I use conditional logic in a field which is part of a group field.

    #18576
    Anh TranAnh Tran
    Keymaster

    Can you please post the code of your meta box?

    #18577
    woorisewoorise
    Participant

    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' => ' ',
    ],

    #18578
    woorisewoorise
    Participant

    *forgot to include it between code tags:

    'placeholder' => ' ',

    #18579
    woorisewoorise
    Participant

    again it strips out the characters. I will use spaces this time:

    & # 1 0 ;

    #18597
    Anh TranAnh Tran
    Keymaster

    Can you post the code on pastebin.com? The forum auto strips all unwanted characters.

    #19282
    Austin PassyAustin Passy
    Participant

    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].

    #19295
    BrianBrian
    Participant

    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 "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,
    Brian

    #19301
    Long NguyenLong Nguyen
    Moderator

    Hi Brian,

    Could you please share your code which uses conditional logic? I will check it on my end.

    #19317

    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.

    https://pastebin.com/SdksUKCM

    #19318

    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)
    #19319
    Austin PassyAustin Passy
    Participant

    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).

    #19330
    Anh TranAnh Tran
    Keymaster

    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?

Viewing 15 posts - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.