Select2 field with Ajax not showing saved value on edit
Select2 field with Ajax not showing saved value on edit

I followed this tutorial to get it set up: https://datatables.net/blog/2017-09-01#C
Looked into the problem and found that I need to support the "initialValue:true" case by responding with { "id": value, "text": "Label to show" }
Now I ran into a couple of problems. I can't seem to find the initialValue or value variables being passed to the server at all. Just as a test I had the server respond with "id" and "text" fields, and even then the select2 field is blank.
This question has an accepted answers - jump to answer
Answers
Can you show me how you have configured your Editor instance please - specifically I'm interested in the Select2 field's configuration, but the whole lot might be of use.
Thanks,
Allan
I forgot about this for a while and finally got around to solving it now. The cascading lists tutorial uses the dependent() method so I looked a little deeper and found that I can just return a values array along with the options array which works to set select2 to the correct value in the editor.
Previously I tried a regular ajax request under the select2 field, which worked but seemed to have a few downsides: the select2 filtering was done server side which wasn't as nice for my use case, and the secondary or dependent field didn't clear out when the primary select was changed, leaving incompatible options selected.
Hopefully this helps if anyone else has the same issue!
Thanks for posting back!
Allan