Trying to understand Data Adapter replacement for InitSelection

2,254 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
Reply all
Reply to author
Forward
0 new messages