We are using a technique that preserves the order of selected options in select2. This technique triggers an event change after it reorder the options. So that might causes the duplication.
In reality, you might cache in the event listener to make sure your code run only once.
Perfect, thank you.
Jut for the record, the event listener was cached as follows:
let select_cache = null
$(document).on('change', '#my_field_id', function(event) {
if (!select_cache) {
setTimeout(() => {
//do your thing
console.log('phones ringing, dude.');
//clear the cache
select_cache = null
}, 100)
select_cache = event
Issue can be marked as resolved.
Intro
We created Meta Box in 2010 to help developers to create custom meta boxes faster and
easier. Now, Meta Box is not only a library with powerful API for custom fields, but also a
framework that helps you control your data the way you want.