Skip to content

Commit 9f62a3f

Browse files
committed
Autocomplete: Cleanup remote-jsonp demo
Fix handling of empty response, remove silly open/close handlers, fix select callback, fix demo description. Closes jquerygh-1542
1 parent 74ccbc1 commit 9f62a3f

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

demos/autocomplete/remote-jsonp.html

+11-18
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,33 @@
2626

2727
$( "#city" ).autocomplete({
2828
source: function( request, response ) {
29-
$.ajax({
29+
$.ajax( {
3030
url: "http://gd.geobytes.com/AutoCompleteCity",
3131
dataType: "jsonp",
3232
data: {
3333
q: request.term
3434
},
3535
success: function( data ) {
36-
response( data );
36+
37+
// Handle 'no match' indicated by [ "" ] response
38+
response( data.length === 1 && data[ 0 ].length === 0 ? [] : data );
3739
}
38-
});
40+
} );
3941
},
4042
minLength: 3,
4143
select: function( event, ui ) {
42-
log( ui.item ?
43-
"Selected: " + ui.item.label :
44-
"Nothing selected, input was " + this.value);
45-
},
46-
open: function() {
47-
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
48-
},
49-
close: function() {
50-
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
44+
log( "Selected: " + ui.item.label );
5145
}
52-
});
53-
});
46+
} );
47+
} );
5448
</script>
5549
</head>
5650
<body>
5751

5852
<div class="ui-widget">
5953
<label for="city">Your city: </label>
60-
<input id="city">
61-
Powered by <a href="http://geonames.org">geonames.org</a>
54+
<input id="city" type="text">
55+
Powered by <a href="http://geobytes.com">geobytes.com</a>
6256
</div>
6357

6458
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
@@ -67,8 +61,7 @@
6761
</div>
6862

6963
<div class="demo-description">
70-
<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>
71-
<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>
64+
<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>
7265
</div>
7366
</body>
7467
</html>

0 commit comments

Comments
 (0)