Cloning a Metabox Group item results in 'property content is undefined'
Support › MB Group › Cloning a Metabox Group item results in 'property content is undefined'Resolved
- This topic has 9 replies, 2 voices, and was last updated 5 years, 10 months ago by
Anh Tran.
-
AuthorPosts
-
June 14, 2019 at 9:18 PM #14969
Yard
ParticipantHi,
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?
June 20, 2019 at 3:28 PM #15016Anh Tran
KeymasterHi, I'm guessing you're using an old version of MB Group. Please update it first.
June 21, 2019 at 12:58 PM #15036Yard
ParticipantHi Anh,
No that's not the case.
June 21, 2019 at 3:42 PM #15038Anh Tran
KeymasterCan you send me the code of the meta box?
June 21, 2019 at 8:45 PM #15043Yard
ParticipantJune 22, 2019 at 11:53 AM #15050Anh Tran
KeymasterYour 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 MB Group extension adds some flexibility for the group title, please see here for details.
June 26, 2019 at 6:29 PM #15103Yard
ParticipantHi 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 ); };
June 27, 2019 at 3:43 PM #15134Anh Tran
KeymasterI got it! Can you try this updated version?
June 28, 2019 at 8:58 PM #15170Yard
ParticipantHi Anh,
Works like a charm! Are you including this fix in the next update?
June 30, 2019 at 3:47 PM #15179Anh Tran
KeymasterYes, I will. It will be available on Monday.
-
AuthorPosts
- You must be logged in to reply to this topic.