Created
March 2, 2016 09:58
-
-
Save bepatrickdavid/906277fb5e59d9da0390 to your computer and use it in GitHub Desktop.
jQuery: automplete
This file contains hidden or 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
//esempio | |
$("#findstore").autocomplete({ | |
minLength:3, | |
source: function(request, response) { | |
var matches = $.map( availableTags, function(tag) { | |
if ( tag.toUpperCase().indexOf(request.term.toUpperCase()) === 0 ) { | |
return tag; | |
} | |
}); | |
response(matches.slice(0, 15)); | |
}, | |
appendTo: $("#city"), | |
open: function(event, ui) { | |
$('.results').off('menufocus hover mouseover mouseenter'); //elimina doppio tap ios | |
}, | |
select: function( e, ui ) { | |
var address = ui.item.value; | |
var dataString = {address: address}; | |
$("input").blur(); //nasconde tastiera al click | |
removeBlock(); | |
$(".maps .loading").show(); | |
//chiamata ajax | |
$.ajax({ | |
url : "../../../../store-api/geo_data.php", | |
data : dataString, | |
type: "POST", | |
success: function(data){ | |
// console.log(data); | |
console.log("Risultato: " + data); | |
geocodeAddress(address, data); | |
createBlock(data); | |
$(".maps .loading").hide(); | |
}, | |
error: function (jxhr, msg, err) { | |
// console.log(msg); | |
} | |
}); | |
} | |
}); | |
//aggiunta lista risultati esterna al campo input | |
$("#findstore").data( "ui-autocomplete" )._renderMenu = function( ul, items ) { | |
var that = this; | |
ul.attr("class", "results"); | |
$.each( items, function( index, item ) { | |
that._renderItemData( ul, item ); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment