Subversion Repositories Sites.obs-saisons.fr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
40 aurelien 1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
	<meta charset="utf-8">
5
	<title>jQuery UI Autocomplete - Multiple, remote</title>
6
	<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7
	<script src="../../jquery-1.4.2.js"></script>
8
	<script src="../../ui/jquery.ui.core.js"></script>
9
	<script src="../../ui/jquery.ui.widget.js"></script>
10
	<script src="../../ui/jquery.ui.position.js"></script>
11
	<script src="../../ui/jquery.ui.autocomplete.js"></script>
12
	<link rel="stylesheet" href="../demos.css">
13
	<style>
14
	.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
15
	</style>
16
	<script>
17
	$(function() {
18
		function split( val ) {
19
			return val.split( /,\s*/ );
20
		}
21
		function extractLast( term ) {
22
			return split( termĀ ).pop();
23
		}
24
 
25
		$( "#birds" ).autocomplete({
26
			source: function( request, response ) {
27
				$.getJSON( "search.php", {
28
					term: extractLast( request.term )
29
				}, response );
30
			},
31
			search: function() {
32
				// custom minLength
33
				var term = extractLast( this.value );
34
				if ( term.length < 2 ) {
35
					return false;
36
				}
37
			},
38
			focus: function() {
39
				// prevent value inserted on focus
40
				return false;
41
			},
42
			select: function( event, ui ) {
43
				var terms = split( this.value );
44
				// remove the current input
45
				terms.pop();
46
				// add the selected item
47
				terms.push( ui.item.value );
48
				// add placeholder to get the comma-and-space at the end
49
				terms.push( "" );
50
				this.value = terms.join( ", " );
51
				return false;
52
			}
53
		});
54
	});
55
	</script>
56
</head>
57
<body>
58
 
59
<div class="demo">
60
 
61
<div class="ui-widget">
62
	<label for="birds">Birds: </label>
63
	<input id="birds" size="50" />
64
</div>
65
 
66
</div><!-- End demo -->
67
 
68
 
69
 
70
<div class="demo-description">
71
<p>Usage: Enter at least two characters to get bird name suggestions. Select a value to continue adding more names.</p>
72
<p>This is an example showing how to use the source-option along with some events to enable autocompleting multiple values into a single field.</p>
73
</div><!-- End demo-description -->
74
 
75
</body>
76
</html>