Skip to content

Commit

Permalink
fix(ReusableComponent): don't break other backend pages if $fieldEl.d…
Browse files Browse the repository at this point in the history
…ata does not exist
  • Loading branch information
timohubois committed Jul 17, 2024
1 parent 7fd4944 commit ece2b90
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Components/ReusableComponent/admin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/* globals acf jQuery */

(function ($) {
if (typeof acf === 'undefined') {
return
}

const select2init = function () {
acf.addAction('select2_init', function ($select, args, settings, field) {
const $fieldEl = field.$el
const fieldName = $fieldEl ? $fieldEl.data('name') || '' : ''

if ($fieldEl.data('name') === 'reusableComponent') {
if (fieldName === 'reusableComponent') {
$select.on('change', { $fieldEl }, function () {
const postId = $(this).val()
const postTitle = $(this).find('option:selected').text()
Expand All @@ -23,7 +28,5 @@
})
}

if (typeof acf !== 'undefined') {
select2init()
}
select2init()
})(jQuery)

0 comments on commit ece2b90

Please sign in to comment.