client/player/css/jq-css/demos/autocomplete/multiple.html
changeset 1 436d4791d7ac
child 57 3a3c15c462f8
equal deleted inserted replaced
0:ecdfc63274bf 1:436d4791d7ac
       
     1 <!DOCTYPE html>
       
     2 <html lang="en">
       
     3 <head>
       
     4 	<meta charset="UTF-8" />
       
     5 	<title>jQuery UI Autocomplete multiple demo</title>
       
     6 	<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
       
     7 	<script type="text/javascript" src="../../jquery-1.4.2.js"></script>
       
     8 	<script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
       
     9 	<script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
       
    10 	<script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
       
    11 	<script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
       
    12 	<link type="text/css" href="../demos.css" rel="stylesheet" />
       
    13 	<script type="text/javascript">
       
    14 	$(function() {
       
    15 		var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];
       
    16 		function split(val) {
       
    17 			return val.split(/,\s*/);
       
    18 		}
       
    19 		function extractLast(term) {
       
    20 			return split(term).pop();
       
    21 		}
       
    22 		
       
    23 		$("#tags").autocomplete({
       
    24 			minLength: 0,
       
    25 			source: function(request, response) {
       
    26 				// delegate back to autocomplete, but extract the last term
       
    27 				response($.ui.autocomplete.filter(availableTags, extractLast(request.term)));
       
    28 			},
       
    29 			focus: function() {
       
    30 				// prevent value inserted on focus
       
    31 				return false;
       
    32 			},
       
    33 			select: function(event, ui) {
       
    34 				var terms = split( this.value );
       
    35 				// remove the current input
       
    36 				terms.pop();
       
    37 				// add the selected item
       
    38 				terms.push( ui.item.value );
       
    39 				// add placeholder to get the comma-and-space at the end
       
    40 				terms.push("");
       
    41 				this.value = terms.join(", ");
       
    42 				return false;
       
    43 			}
       
    44 		});
       
    45 	});
       
    46 	</script>
       
    47 </head>
       
    48 <body>
       
    49 
       
    50 <div class="demo">
       
    51 
       
    52 <div class="ui-widget">
       
    53 	<label for="tags">Tag programming languages: </label>
       
    54 	<input id="tags" size="50" />
       
    55 </div>
       
    56 
       
    57 </div><!-- End demo -->
       
    58 
       
    59 <div class="demo-description">
       
    60 <p>
       
    61 Usage: Type something, eg. "j" to see suggestions for tagging with programming languages. Select a value, then continue typing to add more.
       
    62 </p>
       
    63 <p>
       
    64 This is an example showing how to use the source-option along with some events to enable autocompleting multiple values into a single field.
       
    65 </p>
       
    66 </div><!-- End demo-description -->
       
    67 
       
    68 </body>
       
    69 </html>