JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://dl.dropboxusercontent.com/u/48552248/websites/tiii.me/scripts/partials/_select.js"></script>
<form class="container__inputs cf">
<input type="text" class="tvshow" placeholder="Type-in a TV show" title="Name of a TV show" />
</form>
JavaScript
$(".tvshow").select2({
placeholder: "Type in a TV show",
multiple: true,
maximumSelectionSize: 1,
minimumInputLength: 2,
maximumInputLength: 20,
query: function(query) {
var data = {results: []};
var value = $(".select2-input").val();
$.ajax ({
type: "GET",
url: 'https://dl.dropboxusercontent.com/u/12578403/stack.json',
// url: 'data.json',
dataType: "jsonp",
json: "callbackname",
jsonpCallback:'dotheparse',
crossDomain : true,
success: function (result) {
$.each(result, function (key, item) {
// write everything in an array
data.results.push({id: item.tvdb_id, text: key, poster: item.images.poster, bg: item.fanart });
selectedTVshow = key;
// results = data.results;
// return array
});
query.callback(data);
},
error: function (data) {
// console.log('error');
}
})
}
})