Trying to understand Data Adapter replacement for InitSelection

2,290 views
Skip to first unread message

jri...@nd.edu

unread,
Mar 6, 2015, 2:10:39 PM3/6/15
to sel...@googlegroups.com
I am trying to understand the documentation for select2 4.0 Data adapter, as i am preparing to migrate from 3.5.2

previously i did the following code, which broken down
1) looks at the element's val
2) if id is not blank , ajax call that returns additional data
3) callback

initSelection : function (element, callback) {

var id=$(element).val();
if (id!=="") {
$.ajax("index.cfm/tickets/select2get", {
dataType: 'json',
data: {
nd_event_id: $('#nd_event_id').val(),
passes: '<cfoutput>#rc.location#</cfoutput>',
},
}).done(function(data) { callback(data); });
}
},


How do i translate this to Data Adapter? I am not finding any helpful documentation on this, any help is greatly appreciated

quick...@gmail.com

unread,
Mar 7, 2015, 11:22:58 PM3/7/15
to sel...@googlegroups.com
Having the same issue. Been working on trying to manipulate what is returned from Select2 for a couple of days now. It's quite exhausting, however I think I have learned something. Select2 doesn't seem to have an option for its 'output' of selected options. I assumed since we format the dropdown option to meet the Select2 requirements (id:value, text:value) when we initialize Select2 on the element that it would seem only logical that what would be returned would be the same format. Not the case. And so far I have found no methods in their documentation nor by scanning the select2.js code. I don't think there is a way builtin to the plugin. I could be wrong though, and I hope that I am. Searched high and low for anyone knowing how to do so, and while there seems to be an overwhelming number of people with the same issue, no workable solutions thus far.

Personally on the new Select2 design, I can't make heads or tells of this adapter method they are using. Seems overly complicated for the job. Let me know if you find anything out, ill monitor this thread and do the same if I make any progress.

faruk...@gmail.com

unread,
Mar 11, 2015, 3:01:16 AM3/11/15
to sel...@googlegroups.com
I have same problem, I could not find any sample code for this. Tried different codes but any of the worked.

At the end, I deleted initSelection parts and filled the existing id and text programmatically to select box's first option.

niloy...@gmail.com

unread,
Feb 9, 2016, 9:16:30 AM2/9/16
to select2
@Faruk , please tell me the solution

ell...@optimizely.com

unread,
May 2, 2016, 2:41:10 PM5/2/16
to select2, niloy...@gmail.com
On Tuesday, February 9, 2016 at 3:16:30 PM UTC+1, niloy...@gmail.com wrote:
> @Faruk , please tell me the solution

Faruk, he probably had a `select` HTML element. Then he added an `option` element with the values he desired. Last, he called $('select').select2(...) which is supposed to select the only available option by default. Just my guess.

ell...@optimizely.com

unread,
May 2, 2016, 2:42:15 PM5/2/16
to select2, niloy...@gmail.com, ell...@optimizely.com
Oops that was a response to nilroy

Lilly Snow

unread,
Nov 2, 2025, 2:02:28 PMNov 2
to select2
Anime Salt is an amazing app for anime lovers who enjoy watching their favorite shows anytime. It offers a wide range of anime series with smooth streaming and easy navigation. With Anime Salt, fans can explore both classic and newly released anime in one place.

Brahim Diaz

unread,
Nov 13, 2025, 11:25:11 AM (9 days ago) Nov 13
to select2
Code Crackers Solver is an essential tool for anyone who enjoys wordplay and code-breaking challenges. It analyzes each letter and pattern to provide accurate solutions quickly. With Code Crackers Solver, users can enhance their puzzle-solving skills and tackle even the trickiest codes with ease.

Isaac Glover

unread,
Nov 16, 2025, 3:14:30 AM (7 days ago) Nov 16
to select2

Pizza Catering Sydney mobile wood-fired setup keeps events running smoothly and deliciously, much like how Select2’s data adapter is meant to streamline complex input handling. Just as the pizza team brings fresh ingredients on-demand, your old 3.5.2 workflow pulled dynamic data via AJAX based on the selected value. Migrating to Select2 4.0 simply means adapting that same “load-as-needed” logic into the updated data adapter structure so everything still arrives hot and ready.

Reply all
Reply to author
Forward
0 new messages