Custom Fields
Re-Envisioned
Support Meta Box Group Cloning a Metabox Group item results in 'property content is undefined'

This topic contains 9 replies, has 2 voices, and was last updated by  Anh Tran 3 months, 2 weeks ago.

  • Creator
    Topic
  • #14969
    Resolved
    info@yard.nl
    Participant

    Hi,

    I’m trying to clone a Metabox Group item but the Javascript fails as a result.
    Output:
    Uncaught TypeError: Cannot read property ‘content’ of undefined
    at Object.group.toggle.updateTitle (group.js?ver=1.1.2:65)
    at HTMLDivElement.group.clone.processGroup (group.js?ver=1.1.2:257)
    at HTMLDocument.dispatch (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:3)
    at HTMLDocument.r.handle (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:3)
    at Object.trigger (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:3)
    at Object.a.event.trigger (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:8)
    at HTMLDivElement.<anonymous> (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:3)
    at Function.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:2)
    at a.fn.init.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:2)
    at a.fn.init.trigger (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-position,moxiejs,plupload&ver=5.2.1:3)

    This error occurs in the group.toggle.updateTitle() function in group.js on line 65.

    Is this a known problem and what can I do about it?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #15016

    Anh Tran
    Keymaster

    Hi, I’m guessing you’re using an old version of Meta Box Group. Please update it first.

    #15036

    info@yard.nl
    Participant

    Hi Anh,

    No that’s not the case.

    #15038

    Anh Tran
    Keymaster

    Can you send me the code of the meta box?

    #15043

    info@yard.nl
    Participant
    #15050

    Anh Tran
    Keymaster

    Your code has some specific PHP functions, especially for the group title which relates to the bug. Can you flatten out it to simple PHP string / array to see if the bug still occur?

    By the way, version 1.3.0 of the Meta Box Group extension adds some flexibility for the group title, please see here for details.

    #15103

    info@yard.nl
    Participant

    Hi Anh,

    I’ve downgraded to version 1.2.8 and now it is al working fine.
    The code below is the one that works.

    /**
         * Update group title.
         *
         * @param index   Group clone index.
         * @param element Group element.
         */
        group.toggle.updateTitle = function ( index, element ) {
            var $group = $( element ),
                $title = $group.find( '> .rwmb-group-title, > .rwmb-input > .rwmb-group-title' ),
                options = $title.data( 'options' ),
                content = '';
    
            function processField( fieldId, separator ) {
                separator = separator || '';
    
                var $field = $group.find( ':input[name*="[' + fieldId + ']"]' ),
                    fieldValue = $field.val();
    
                if ( $field.is( 'select' ) ) {
                    fieldValue = $field.find( 'option:selected' ).text();
                }
    
                if ( fieldValue ) {
                    content += ( content ? separator : '' ) + fieldValue;
                }
    
                // Update title when field's value is changed.
                if ( ! $field.data( 'update-group-title' ) ) {
                    $field.on( 'keyup change', _.debounce( function () {
                        group.toggle.updateTitle( 0, element );
                    }, 250 ) ).data( 'update-group-title', true );
                }
            }
    
            if ( 'undefined' === typeof options || 'undefined' === typeof options.type ) {
                return;
            }
    
            if ( 'text' === options.type ) {
                content = options.content.replace( '{#}', index );
            }
            if ( 'field' === options.type ) {
                var fieldId = options.field;
    
                // Multiple fields.
                if ( -1 !== fieldId.indexOf( ',' ) ) {
                    options.separator = options.separator || ' ';
                    var fieldIds = fieldId.split( ',' );
                    fieldIds.forEach( function ( value ) {
                        processField( value.trim(), options.separator );
                    } );
                } else {
                    processField( fieldId );
                }
            }
            $title.text( content );
        };
    #15134

    Anh Tran
    Keymaster

    I got it! Can you try this updated version?

    https://pastebin.com/Dbjsz5Pw

    #15170

    info@yard.nl
    Participant

    Hi Anh,

    Works like a charm! Are you including this fix in the next update?

    #15179

    Anh Tran
    Keymaster

    Yes, I will. It will be available on Monday.

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.