I'm using Select2 4.0.0-rc.2.
The Options page states the following about initSelection
In the past, Select2 required an option called
initSelection
that was defined whenever a custom data source was being used, allowing for the initial selection for the component to be determined. This has been replaced by thecurrent
method on the data adapter.
I only found examples for older versions of Select2 that use initSelection
(see Setting initial values on load with Select2 with Ajax)
How can I load default data with data adapter?
here is my initial code (is twig)
$("#{{ id }}").select2({
ajax: {
url: "{{ path(attr.path) }}",
dataType: 'json',
{% if attr.placeholder is defined %}
placeholder: '{{ attr.placeholder }}',
{% endif %}
delay: 250,
data: function (term) {
return term;
},
processResults: function (data) {
return {results: data};
}
},
templateResult: function(data){
return '<img width="30" src="'+data.image+'">'+data.text;
},
templateSelection: function(data){
return '<img width="30" src="'+data.image+'">'+data.text;
},
cache: true,
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 2
});
If it possible i want setup always visible options and have ajax other,