Select2 field with Ajax not showing saved value on edit

Select2 field with Ajax not showing saved value on edit

broder22broder22 Posts: 5Questions: 2Answers: 1
edited September 2019 in Free community support

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

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    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

  • broder22broder22 Posts: 5Questions: 2Answers: 1
    Answer ✓

    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!

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Thanks for posting back!

    Allan

This discussion has been closed.