Skip to content

Instantly share code, notes, and snippets.

@heanfig
Created June 1, 2016 06:30
Show Gist options
  • Save heanfig/7da5766f7c8c8550ed04e6727d672c5b to your computer and use it in GitHub Desktop.
Save heanfig/7da5766f7c8c8550ed04e6727d672c5b to your computer and use it in GitHub Desktop.
load remote query typeahead
var states = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: Metronic.getAJAXURL() + "general/general/BuscarCiudades?query=%QUERY",
filter: function (ciudades) {
return $.map(ciudades, function (ciudad) {
return {
num: ciudad.id_ciudad,
nombre: ciudad.ciudad_nombre.toLowerCase(),
nombredepartamento: ciudad.estado_nombre.toLowerCase()
};
});
}
},
limit: 1000
});
states.initialize();
$('#typeahead_ciudad').typeahead(null, {
display: 'nombre',
name: 'productos_UNSPSC',
source: states.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'No se encontraron coincidencias con el criterio de búsqueda',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<div class="item-result" style="text-transform: capitalize;">{{nombre}}<div class="clase_placeholder">{{ nombredepartamento }}</div></div>')
}
});
$('#typeahead_ciudad').on('typeahead:selected', function (e, suggestion, name) {
$scope.ingresardireccion.ciudad = suggestion.num;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment