acf-dynamic-ajax-select-example
acf-dynamic-ajax-select-example copied to clipboard
How to get value of Select2?
First of all thank you for these examples, they have helped me enormously with manupulating some fields on the admin side. Any chance you know how to get the value of a select2 field (im using the taxonomy ACF field). Basically want to change some checkbox group options based on what taxonomy they select. I was able to get most to work but for some reason cant figure out how to get the selected value of this field. See my code below, .Val() comes back null
var selManufacturer = acf.getField('field_629a3d70a424a'); var manufacturer = selManufacturer.val(); console.log(selManufacturer.data); console.log(manufacturer); if (!manufacturer) { // no state selected // don't need to do anything else console.log('no mid found, aborting'); return; }
That looks like the way I'd try to do it. It that's not it then I don't know. What is being logged to console?
selManufacturer returns an object but manufacturer returns null