acf-dynamic-ajax-select-example icon indicating copy to clipboard operation
acf-dynamic-ajax-select-example copied to clipboard

How to get value of Select2?

Open CFusionMM opened this issue 2 years ago • 2 comments

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; }

CFusionMM avatar Jul 10 '22 16:07 CFusionMM

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?

Hube2 avatar Jul 11 '22 11:07 Hube2

selManufacturer returns an object but manufacturer returns null

CFusionMM avatar Jul 11 '22 15:07 CFusionMM