Hi Guys,
I've been receiving the followin error when I try to do an ajax based options source.
Uncaught Error: No select2/compat/inputData
I can't seem to find any reference to it.
So i found this stack overflow example.
But continue to recieve the same error. (I thought it might be a pathing issue, but can't seem to resolve it, also I am not using any kind of server technology, jsut trying to call the json file directly as seen in the code below.) Am I missing something really obvious?
So, I tried changing to the CDN and received this error:
Uncaught ReferenceError: require is not defined
Project Structure:
root
--src
-----main
-------\webapp
-----------\json
--------------\select2_test.json
-----------\select2_test_ajax.html
Code that calls:
Select2_test_ajax.html:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link href="resources/css/bootstrap.css">
<link href="//
cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/css/select2.min.css" rel="stylesheet" />
</head>
<body>
<div class="row">
<form class="form">
<div class="form-group">
<input class='form-control col-lg-5 itemSearch' type='text' placeholder='select item' />
</div>
</form>
</div>
<script type="text/javascript" src="resources/js/jquery-2.1.3.js"></script>
<script type="text/javascript" src="resources/js/bootstrap.js"></script>
<script src="//
cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/js/select2.min.js"></script>
<script>
$(document).ready(function(){
$(".itemSearch").select2({
placeholder: "Search for an Item",
minimumInputLength: 2,
ajax: {
url: "json/select2_test.json",
dataType: 'json',
type: "GET",
quietMillis: 50,
data: function (term) {
return {
term: term
};
},
results: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.completeName,
slug: item.slug,
id:
item.id
}
})
};
}
}
});
});
</script>
</body>
</html>
select2_test.json:
[{"itemName":"Test item no. 1","id":5},
{"itemName":"Test item no. 2","id":6},
{"itemName":"Test item no. 3","id":7},
{"itemName":"Test item no. 4","id":8},
{"itemName":"Test item no. 5","id":9},
{"itemName":"Test item no. 6","id":10},
{"itemName":"Test item no. 7","id":11}]