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 + ']"]' );