A
A
Alexander Pantyukhov2016-06-21 14:18:20
JavaScript
Alexander Pantyukhov, 2016-06-21 14:18:20

Why is the list not loading in select2?

Good day!
The code uses two select2s (unfortunately they were not written by me and they don’t let me rewrite the code). The first is the parent of the second. Everything is configured in such a way that if the user changes something in the first one, then the list is loaded into the second one, which depends on the selected values ​​in the first one. Everything works well until the management needed to select the data not by hand, but by choosing a certain "preset". There were no problems with the usual (independent) selects, but with these, leapfrog began. If there was nothing on the first one and I add a value like this, $("#selectedCurrency").select2('val',[2,3,6,9])then everything is fine, but not so much with the second one. Such actions do not lead to anything. in the second select no list came and he has nothing to choose. In this case, the change event occurs for the first one, but nothing happens with the second one.
Tell me how to solve this problem? I've been struggling with this for more than a day now.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2016-06-21
@lega

If there is no data in the select, then they must first be added (something like .select2('data', {results:[...]}) for version 3.x).
Here is an example where there is a setting for dynamic loadable data: plnkr.co/edit/RK7uuc?p=preview

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question