I had been using version 3 in an ACF/Wordpress environment and it was working fine. Then ACF made some updates and so did Select2 and now a couple of elements just won’t work.
So this is Select2 version 4 with ACF Pro v5.7.10
The code I had first loaded various values from the DB into the select2 - this still works fine.
Then it tried to programmatically select those values. In this case it’s languages. For example, this used to select ‘English’ from the list:
defLanguage = 'English';
$('#s2id_acf-field_58b7183e6cd9b-input').select2("data", {id: defLanguage, text: defLanguage}, true);
Sometimes there was an array of languages:
var lArray = [];
lArray.push ({id: English, text: English});
lArray.push ({id: Spanish, text: Spanish});
$('#s2id_acf-field_57ed5364ea164-input').select2("data", lArray, true);
These two don’t work now. No items are selected from the Select2 fields.
There’s a second problem, too.
When someone went into the language field and manually selected or changed the items there, it triggered a function to change values elsewhere:
$('#s2id_acf-field_57ed5364ea164-input').focusout(function () {
// get new value
newValue = $('#s2id_acf-field_57ed5364ea164-input').select2("val");
newValue = newValue.toString();
// and then do stuff with the new values
});
But this is never triggered. Evidently focusout is not called.
I’ve tried a million (ok, exaggeration - lots of) different ideas to try and fix this and ACF haven’t been any help at all.
Can anyone help with these two please?