aboutsummaryrefslogtreecommitdiffstats
path: root/demos/autocomplete
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2015-04-20 14:20:59 +0200
committerJörn Zaefferer <joern.zaefferer@gmail.com>2015-04-20 16:55:26 +0200
commit9f62a3faf638c964bbf37791258dd19faa566a2a (patch)
treeba2e5fe6c7c6417b36fe895763d84fe51fbce460 /demos/autocomplete
parent74ccbc18a414be9f78f6765b2b6c8be29c5019a9 (diff)
downloadjquery-ui-9f62a3faf638c964bbf37791258dd19faa566a2a.tar.gz
jquery-ui-9f62a3faf638c964bbf37791258dd19faa566a2a.zip
Autocomplete: Cleanup remote-jsonp demo
Fix handling of empty response, remove silly open/close handlers, fix select callback, fix demo description. Closes gh-1542
Diffstat (limited to 'demos/autocomplete')
-rw-r--r--demos/autocomplete/remote-jsonp.html29
1 files changed, 11 insertions, 18 deletions
diff --git a/demos/autocomplete/remote-jsonp.html b/demos/autocomplete/remote-jsonp.html
index 84c6957e0..0d71dae9a 100644
--- a/demos/autocomplete/remote-jsonp.html
+++ b/demos/autocomplete/remote-jsonp.html
@@ -26,39 +26,33 @@
$( "#city" ).autocomplete({
source: function( request, response ) {
- $.ajax({
+ $.ajax( {
url: "http://gd.geobytes.com/AutoCompleteCity",
dataType: "jsonp",
data: {
q: request.term
},
success: function( data ) {
- response( data );
+
+ // Handle 'no match' indicated by [ "" ] response
+ response( data.length === 1 && data[ 0 ].length === 0 ? [] : data );
}
- });
+ } );
},
minLength: 3,
select: function( event, ui ) {
- log( ui.item ?
- "Selected: " + ui.item.label :
- "Nothing selected, input was " + this.value);
- },
- open: function() {
- $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
- },
- close: function() {
- $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
+ log( "Selected: " + ui.item.label );
}
- });
- });
+ } );
+ } );
</script>
</head>
<body>
<div class="ui-widget">
<label for="city">Your city: </label>
- <input id="city">
- Powered by <a href="http://geonames.org">geonames.org</a>
+ <input id="city" type="text">
+ Powered by <a href="http://geobytes.com">geobytes.com</a>
</div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
@@ -67,8 +61,7 @@
</div>
<div class="demo-description">
-<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are cities, displayed when at least two characters are entered into the field.</p>
-<p>In this case, the datasource is the <a href="http://geonames.org">geonames.org webservice</a>. While only the city name itself ends up in the input after selecting an element, more info is displayed in the suggestions to help find the right entry. That data is also available in callbacks, as illustrated by the Result area below the input.</p>
+<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are cities, displayed when at least three characters are entered into the field. The datasource is the <a href="http://geobytes.com">geobytes.com webservice</a>. That data is also available in callbacks, as illustrated by the Result area below the input.</p>
</div>
</body>
</html>