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/48552248/websites/tiii.me/shows.json',
// url: 'data.json',
dataType: "jsonp",
json: "callbackname",
crossDomain : true,
success: function (result) {
$.each(result, function (i, show) {
// write everything in an array
data.results.push({id: this.tvdb_id, text: this.title, poster: this.images.poster, bg: this.fanart });
console.log(this.title);
selectedTVshow = this.title;
// results = data.results;
// return array
query.callback(data);
})
},
error: function (data) {
// console.log('error');
}
})
}
})