TypeError: logics is undefined

Support MB Conditional Logic TypeError: logics is undefinedResolved

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #19335

    Dear Anh,

    I managed to reproduce the error by entering this code in a WYSIWYG field with a 'hidden' condition:
    <header id="entry-header" class="entry__header yr-entry-header" data-rapid-sec="{&quot;entry-header&quot;:&quot;entry-header&quot;}"></header>

    Somehow this makes the value of the data-conditions attribute invalid JSON.

    (It turned out one of my co-workers pasted this messy HTML from another site in a WYSIWYG-field, this is part of the HTML)

    Hope this helps..?

    Best,

    AJ

    #19343
    Austin PassyAustin Passy
    Participant

    Sorry, I am unable to paste my code as it's 20 post types, and thousands of custom fields.

    But I was able to spot incorrect JSON in the data-conditions attribute which may help. It would seem that double quoted aren't getting encoded properly.

    When I changed the get_conditional_html (and reverted the JS changes) I no longer see the logics errors.

    
    esc_attr( htmlspecialchars( wp_json_encode( $conditions ), ENT_QUOTES, 'UTF-8' ) )
      
    

    This was the json condition (part of it that didn't get encoded/escaped properly):

    
    "desc": "Alphanumeric, no special characters except for " - ".",
    

    Hope this helps.

    #19357
    Anh TranAnh Tran
    Keymaster

    Thanks a lot for your feedback! Looks like the json encode is the problem. I'll check and fix that.

    #19360
    Anh TranAnh Tran
    Keymaster

    Hey guys, can you help me to test the fix before releasing a new version? Please try changing parse_conditions function to:

    private function parse_conditions( $conditions ) {
        $output = [];
        if ( ! empty( $conditions['visible'] ) ) {
            $output['visible'] = $this->parse_condition( $conditions['visible'] );
        }
        if ( ! empty( $conditions['hidden'] ) ) {
            $output['hidden'] = $this->parse_condition( $conditions['hidden'] );
        }
        return $output;
    }

    The previous code does JSON-encode all field settings, which contains something like field description and value, which might break the JSON. The new code only encodes the conditions, which eliminate this issue and might improve the performance as well.

    #19377
    Austin PassyAustin Passy
    Participant

    Thanks, I will test this today and report back.

    #19380
    Austin PassyAustin Passy
    Participant

    Validated the updated function is working without issues.

    #19387
    Anh TranAnh Tran
    Keymaster

    Thank you!

    I've released a new version for MB Conditional Logic. The update for AIO will come next week.

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