Last active
January 25, 2017 11:18
-
-
Save iaditya/9908c190e529645991f3c2a11581f1d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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