How to set default value on Select2 Autocomplete via hook_alter

What’s the best way to set a default value to a Select2 autocomplete field widget on form load (I’m using a reference view to populate options). I’ve tried a ton of different variations from within form_alter with no success, such as…

$form['field_name']['widget']['#select2']['id'] = 12

I can set the hidden <select> element with…

$form['field_name']['widget']['#default_value'] = 12

…but this value doesn’t populate into the Select2 Widget.

I’ve combed through docs and issues without finding a solution. What am I missing?


Go to Source of this post
Author Of this post: Yuckle
Title Of post: How to set default value on Select2 Autocomplete via hook_alter
Author Link: {authorlink}