Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iaditya
Last active January 25, 2017 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaditya/9908c190e529645991f3c2a11581f1d5 to your computer and use it in GitHub Desktop.
Save iaditya/9908c190e529645991f3c2a11581f1d5 to your computer and use it in GitHub Desktop.
<script>
$(".cd-select").select2({
placeholder: 'Click and type',
allowClear: true,
ajax: {
url: function (params) {
return '/citiesDistricts/searchDistricts.json?q=' + params.term;
},
dataType: 'json',
delay: 500,
processResults: function (data, params) {
//console.log(JSON.stringify(data.citiesDistricts));
return {
results: data.citiesDistricts,
};
},
cache: false
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected repository's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the repository name is shown preselected
//var id = $(element).val();
var id = 1; // need to pass here id
if (id !== "") {
$.ajax('/citiesDistricts/fetchDistrict/' + id, {
dataType: "json",
}).done(function(data) {
// this data returns the Entity
console.log(data);
});
}
},
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment