From 9f62a3faf638c964bbf37791258dd19faa566a2a Mon Sep 17 00:00:00 2001 From: Jörn Zaefferer Date: Mon, 20 Apr 2015 14:20:59 +0200 Subject: Autocomplete: Cleanup remote-jsonp demo Fix handling of empty response, remove silly open/close handlers, fix select callback, fix demo description. Closes gh-1542 --- demos/autocomplete/remote-jsonp.html | 29 +++++++++++------------------ 1 file 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 ); } - }); - }); + } ); + } );
- - Powered by geonames.org + + Powered by geobytes.com
@@ -67,8 +61,7 @@
-

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.

-

In this case, the datasource is the geonames.org webservice. 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.

+

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 geobytes.com webservice. That data is also available in callbacks, as illustrated by the Result area below the input.

-- cgit v1.2.3