Uncaught TypeError: Cannot read property 'type' of undefined
- This topic has 2 replies, 2 voices, and was last updated 5 years, 8 months ago by
fexy.
-
AuthorPosts
-
September 4, 2019 at 2:35 AM #15969
fexy
ParticipantAfter updating our Meta Box plugins to the latest versions (Meta Box v5.1.2 and MB 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 thegroup.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 thedata-options
attribute, and then references the option's title field which is undefined since it didn't actually find the group title element ordata-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 theoptions
variable is undefined, which causes the conditional statement ofif ( '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 + ']"]' );
September 5, 2019 at 12:27 AM #15990Anh Tran
KeymasterHi 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.
September 5, 2019 at 10:33 PM #16000fexy
ParticipantHi 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
-
AuthorPosts
- You must be logged in to reply to this topic.