Support Forum
Support › Meta Box Group › Cloning a Metabox Group item results in 'property content is undefined'Resolved
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?
Hi, I'm guessing you're using an old version of Meta Box Group. Please update it first.
Hi Anh,
No that's not the case.
Can you send me the code of the meta box?
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.
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 );
};
I got it! Can you try this updated version?
Hi Anh,
Works like a charm! Are you including this fix in the next update?
Yes, I will. It will be available on Monday.