Skip to content

Commit ece2b90

Browse files
committed
fix(ReusableComponent): don't break other backend pages if $fieldEl.data does not exist
1 parent 7fd4944 commit ece2b90

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Components/ReusableComponent/admin.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/* globals acf jQuery */
22

33
(function ($) {
4+
if (typeof acf === 'undefined') {
5+
return
6+
}
7+
48
const select2init = function () {
59
acf.addAction('select2_init', function ($select, args, settings, field) {
610
const $fieldEl = field.$el
11+
const fieldName = $fieldEl ? $fieldEl.data('name') || '' : ''
712

8-
if ($fieldEl.data('name') === 'reusableComponent') {
13+
if (fieldName === 'reusableComponent') {
914
$select.on('change', { $fieldEl }, function () {
1015
const postId = $(this).val()
1116
const postTitle = $(this).find('option:selected').text()
@@ -23,7 +28,5 @@
2328
})
2429
}
2530

26-
if (typeof acf !== 'undefined') {
27-
select2init()
28-
}
31+
select2init()
2932
})(jQuery)

0 commit comments

Comments
 (0)