Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 37fe2cc

Browse files
committed
listview filter: autocomplete demo
issue #5096
1 parent 4437c3d commit 37fe2cc

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

docs/demos/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ <h2>Demos</h2>
4949
<li data-role="list-divider">Listviews</li>
5050
<li><a href="listviews/listview.html" data-ajax="false">Listviews</a></li>
5151
<li><a href="listviews/listview-filter-autodividers.html" data-ajax="false">Listview Filter &amp; Autodividers</a></li>
52+
<li><a href="listviews/listview-filter-autocomplete.html" data-ajax="false">Autocomplete from a remote source using listview</a></li>
5253
<li><a href="listviews/listview-forms.html" data-ajax="false">Listview Forms</a></li>
5354
<li><a href="listviews/collapsible-listview.html" data-ajax="false">Collapsible listview</a></li>
5455
<li data-role="list-divider">Grids</li>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Listview Filter &amp; Autodividers - jQuery Mobile Demos</title>
7+
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css">
8+
<link rel="stylesheet" href="../_assets/css/jqm-demos.css">
9+
<script src="../../../js/jquery.js"></script>
10+
<script src="../_assets/js/jqm-demos.js"></script>
11+
<script src="../../../js/"></script>
12+
<script>
13+
$( document ).ready( function() {
14+
$( "#autocomplete" ).listview({
15+
filter: true
16+
});
17+
18+
$( "#autocomplete" ).on( "listviewbeforefilter",
19+
function( e, data ) {
20+
var $ul = $( this ),
21+
$input = $( data.input ),
22+
value = $input.val(),
23+
html = "";
24+
$ul.html( "" );
25+
if ( value && value.length > 2 ) {
26+
$ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>");
27+
$ul.listview( "refresh" );
28+
$.ajax({
29+
url: "http://gd.geobytes.com/AutoCompleteCity",
30+
dataType: "jsonp",
31+
crossDomain: true,
32+
data: {
33+
q: $input.val()
34+
}
35+
}).
36+
then(
37+
function( response ) {
38+
$.each( response, function( i, val ) {
39+
html += "<li>" + val + "</li>";
40+
});
41+
$ul.html( html );
42+
$ul.listview( "refresh" );
43+
}
44+
)
45+
}
46+
}
47+
);
48+
});
49+
</script>
50+
</head>
51+
<body>
52+
<div data-role="page">
53+
54+
<div data-role="header" data-theme="f">
55+
<h1>Listview Autocomplete</h1>
56+
<a href="../" data-icon="home" data-iconpos="notext" data-ajax="false">Home</a>
57+
</div><!-- /header -->
58+
59+
<div data-role="content">
60+
61+
<div class="content-primary">
62+
63+
<div data-demo-html="true" data-demo-js="true">
64+
<ul id="autocomplete" data-filter-theme="d"></ul>
65+
</div><!--/demo-html -->
66+
67+
68+
</div><!--/content-primary -->
69+
70+
</div><!-- /content -->
71+
72+
<div class="jqm-footer">
73+
<p class="jqm-version"></p>
74+
<p>&copy; 2012 jQuery Foundation and other contributors</p>
75+
</div><!-- /jqm-footer -->
76+
77+
</div><!-- /page -->
78+
79+
</body>
80+
</html>

0 commit comments

Comments
 (0)