Support Forum
Support › Meta Box Group › Uncaught TypeError: Cannot read property 'type' of undefinedResolved
After updating our Meta Box plugins to the latest versions (Meta Box v5.1.2 and Meta Box Group v1.3.4) my Meta Box groups are suddenly breaking and throwing the error Uncaught TypeError: Cannot read property 'type' of undefined
.
Digging into the code it appears that the group.toggle.updateTitle
function in the group.js
file is looking for the group title element as a direct descendant (the selector is "> .rwmb-group-title, > .rwmb-input > .rwmb-group-title"
) but the group title element is nested under the .rwmb-group-title-wrapper
element so it is not a direct descendant. The code assumes it finds the group title element successfully, tries to get the options from the data-options
attribute, and then references the option's title field which is undefined since it didn't actually find the group title element or data-options
attribute.
Below is an excerpt of the code I'm looking at in the group.js
file. The $title
variable has a length of zero (no elements found) so therefore the options
variable is undefined, which causes the conditional statement of if ( 'text' === options.type )
to fail.
Is this a known bug and if so is there a work-around or fix? We haven't customized anything so I don't think this is an issue with just our implementation.
/**
* 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;
if ( 'text' === options.type ) {
content = options.content.replace( '{#}', index );
}
if ( 'field' === options.type ) {
var fieldId = $title.data( 'options' ).field,
$field = $group.find( ':input[name*="[' + fieldId + ']"]' );
Hi fexy,
Your JS code is different from mine. Mine is:
$title = $group.find( '> .rwmb-group-title-wrapper > .rwmb-group-title, > .rwmb-input > .rwmb-group-title-wrapper > .rwmb-group-title' ),
So, I guess there's some caching issue here. Please cleane the browser cache and try again.
Hi Anh,
I think you're right. I came in this morning to find it working and the code now matches yours. When I was troubleshooting yesterday I saw the version number on the end of the group.js URL so I assumed that would have changed so it couldn't have cached. In hindsight I should have forced a reload just to be sure but I guess this means that the group.js script changed but the version param didn't?
Regardless, it is working now. Thanks for the quick reply!
-Bob