AUI Select2 - how to make it autocomplete dynamically

I want to develop multi-select text box with autocomplete with users, groups and space keys using AUI Select2. I am able to do this with static options but want to fetch users, groups and space names dynamically and populate select options. please suggest me some useful code snippets to do the same or let me know if there are any out of the box components available.

it’s just a wrapper for select2 that gives the component the right look and feel. the documentation for select2 is online and very good.

Thanks, @justin_shapiro for the reply, I tried to use regular features of select2, but I am getting below errors, how to upgrade select2 library version in confluence add-ons? how to call multiple REST APIs (like users, groups and spaces etc…,) for populating options for select2?

Uncaught Error: Option ‘multiple’ is not allowed for Select2 when attached to a element.

Uncaught Error: Option ‘ajax’ is not allowed for Select2 when attached to a element.

When attaching any select2 to a input, you MUST use <input type='hidden' name='yourname' id='yourid' /> instead of a select element.

Simply put, for a static field, use select elements. For a dynamic field, use input type='hidden'.

Thanks, @sfbehnke for the answer, its working like a charm!!

1 Like

Glad you got it working.