source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/docs/autocomplete.html@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 19.4 KB
Line 
1<p>
2<ul class="UIAPIPlugin-toc">
3<li><a href="#overview">Overview</a></li>
4<li><a href="#options">Options</a></li>
5<li><a href="#events">Events</a></li>
6<li><a href="#methods">Methods</a></li>
7<li><a href="#theming">Theming</a></li>
8</ul>
9<div class="UIAPIPlugin">
10 <h1>jQuery UI Autocomplete</h1>
11 <div id="overview">
12 <h2 class="top-header">Overview</h2>
13 <div id="overview-main">
14 You've seen functionality like Autocomplete before. Anytime you've done a search on Google for instance or typed in a url into your location bar of your browser. You would start to type and as you typed a narrowing list of options would be presented to you. This is the functionality that the Autocomplete plugin can provide you and your web site.
15</p><p>Autocomplete, added to an input field, enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering.
16</p><p>By giving an Autocomplete field focus or entering something into it, the plugin starts searching for entries that match and displays a list of values to choose from. By entering more characters, the user can filter down the list to better matches.
17</p><p>This can be used to enter previous selected values, for example you could use Autocomplete for entering tags, to complete an address, you could enter a city name and get the zip code, or maybe enter email addresses from an address book.
18</p><p>You can pull data in from a local and/or a remote source: Local is good for small data sets (like an address book with 50 entries), remote is necessary for big data sets, like a database with hundreds or millions of entries to select from.
19</p><p>To customize the widget to work with these varied cases, you implement the source option. There are three variations:
20</p>
21<ul><li> an Array with local data
22</li><li> a String, specifying a URL
23</li><li> a Callback
24</li></ul>
25<p>The local data can be a simple Array of Strings, or it contains Objects for each item in the array, with a label or value property or both. The label property is displayed in the suggestion menu, the value will be inserted into the input element after the user selected something from the menu. If just one is specified, it will be used for both, eg. if you provide only value-properties, they will also be used as the label.
26</p><p>When a String is used, the Autocomplete plugin expects that string to point to a resource to return JSON data. It can be on the same host or on a different one (must provide JSONP). The data itself can be in the same format as the local data described above.
27</p><p>The third variation, the callback, provides the most flexibility, and can be used to connect any datasource to the Autocomplete. The callback gets two arguments:
28</p>
29<ul><li> A request object, with a single property called "term", which refers to the value currently in the text input. For example, when the user entered "new yo" in a city autocomplete, term equals "new yo".
30</li><li> A response callback, which expects a single argument to contain the data to suggest to the user. This data should be filtered based on the provided term, and can be in any of the formats described above for simple local data (String-Array or Object-Array with label/value/both properties).
31</li></ul>
32The demos all focus on different variations of the source-option - look for the one that matches your usecase, and take a look at the code.
33 </div>
34 <div id="overview-dependencies">
35 <h3>Dependencies</h3>
36 <ul>
37<li>UI Core</li>
38<li>UI Widget</li>
39</ul>
40 </div>
41 <div id="overview-example">
42 <h3>Example</h3>
43 <div id="overview-example" class="example">
44<ul><li><a href="#demo"><span>Demo</span></a></li><li><a href="#source"><span>View Source</span></a></li></ul>
45<p><div id="demo" class="tabs-container" rel="300">
46A simple jQuery UI Autocomplete.<br />
47</p>
48<pre>$(&quot;input#autocomplete&quot;).autocomplete({
49 source: [&quot;c++&quot;, &quot;java&quot;, &quot;php&quot;, &quot;coldfusion&quot;, &quot;javascript&quot;, &quot;asp&quot;, &quot;ruby&quot;]
50});
51</pre>
52<p></div><div id="source" class="tabs-container">
53</p>
54<pre>&lt;!DOCTYPE html&gt;
55&lt;html&gt;
56&lt;head&gt;
57 &lt;link type=&quot;text/css&quot; href=&quot;http://jqueryui.com/latest/themes/base/ui.all.css&quot; rel=&quot;stylesheet&quot; /&gt;
58 &lt;script type=&quot;text/javascript&quot; src=&quot;http://jqueryui.com/latest/jquery-1.3.2.js&quot;&gt;&lt;/script&gt;
59 &lt;script type=&quot;text/javascript&quot; src=&quot;http://jqueryui.com/latest/ui/jquery.ui.core.js&quot;&gt;&lt;/script&gt;
60 &lt;script type=&quot;text/javascript&quot; src=&quot;http://jqueryui.com/latest/ui/jquery.ui.widget.js&quot;&gt;&lt;/script&gt;
61 &lt;script type=&quot;text/javascript&quot; src=&quot;http://jqueryui.com/latest/ui/jquery.ui.autocomplete.js&quot;&gt;&lt;/script&gt;
62 &lt;script type="text/javascript"&gt;
63 $(document).ready(function(){
64 $(&quot;input#autocomplete&quot;).autocomplete({
65 source: [&quot;c++&quot;, &quot;java&quot;, &quot;php&quot;, &quot;coldfusion&quot;, &quot;javascript&quot;, &quot;asp&quot;, &quot;ruby&quot;]
66});
67 });
68 &lt;/script&gt;
69&lt;/head&gt;
70&lt;body style="font-size:62.5%;"&gt;
71
72&lt;input id=&quot;autocomplete&quot; /&gt;
73
74&lt;/body&gt;
75&lt;/html&gt;
76</pre>
77<p></div>
78</p><p></div>
79 </div>
80 </div>
81 <div id="options">
82 <h2 class="top-header">Options</h2>
83 <ul class="options-list">
84
85<li class="option" id="option-delay">
86 <div class="option-header">
87 <h3 class="option-name"><a href="#option-delay">delay</a></h3>
88 <dl>
89 <dt class="option-type-label">Type:</dt>
90 <dd class="option-type">Integer</dd>
91
92 <dt class="option-default-label">Default:</dt>
93 <dd class="option-default">300</dd>
94
95 </dl>
96 </div>
97 <div class="option-description">
98 <p>The delay in milliseconds the autocomplete waits after a keystroke to activate itself. A zero-delay makes sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive.</p>
99 </div>
100 <div class="option-examples">
101 <h4>Code examples</h4>
102 <dl class="option-examples-list">
103
104<dt>
105 Initialize a autocomplete with the <code>delay</code> option specified.
106</dt>
107<dd>
108<pre><code>$('.selector').autocomplete({ delay: 0 });</code></pre>
109</dd>
110
111
112<dt>
113 Get or set the <code>delay</code> option, after init.
114</dt>
115<dd>
116<pre><code>//getter
117var delay = $('.selector').autocomplete('option', 'delay');
118//setter
119$('.selector').autocomplete('option', 'delay', 0);</code></pre>
120</dd>
121
122 </dl>
123 </div>
124</li>
125
126
127<li class="option" id="option-minLength">
128 <div class="option-header">
129 <h3 class="option-name"><a href="#option-minLength">minLength</a></h3>
130 <dl>
131 <dt class="option-type-label">Type:</dt>
132 <dd class="option-type">Integer</dd>
133
134 <dt class="option-default-label">Default:</dt>
135 <dd class="option-default">1</dd>
136
137 </dl>
138 </div>
139 <div class="option-description">
140 <p>The minimum number of characters a user has to type before the autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items, where a single character would match a few thousand items.</p>
141 </div>
142 <div class="option-examples">
143 <h4>Code examples</h4>
144 <dl class="option-examples-list">
145
146<dt>
147 Initialize a autocomplete with the <code>minLength</code> option specified.
148</dt>
149<dd>
150<pre><code>$('.selector').autocomplete({ minLength: 0 });</code></pre>
151</dd>
152
153
154<dt>
155 Get or set the <code>minLength</code> option, after init.
156</dt>
157<dd>
158<pre><code>//getter
159var minLength = $('.selector').autocomplete('option', 'minLength');
160//setter
161$('.selector').autocomplete('option', 'minLength', 0);</code></pre>
162</dd>
163
164 </dl>
165 </div>
166</li>
167
168
169<li class="option" id="option-source">
170 <div class="option-header">
171 <h3 class="option-name"><a href="#option-source">source</a></h3>
172 <dl>
173 <dt class="option-type-label">Type:</dt>
174 <dd class="option-type">String, Array, Callback</dd>
175
176 <dt class="option-default-label">Default:</dt>
177 <dd class="option-default">none, must be specified</dd>
178
179 </dl>
180 </div>
181 <div class="option-description">
182 <p>Defines the data to use, must be specified. See Overview section for more details, and look at the various demos.
183</p>
184 </div>
185 <div class="option-examples">
186 <h4>Code examples</h4>
187 <dl class="option-examples-list">
188
189<dt>
190 Initialize a autocomplete with the <code>source</code> option specified.
191</dt>
192<dd>
193<pre><code>$('.selector').autocomplete({ source: [&quot;c++&quot;, &quot;java&quot;, &quot;php&quot;, &quot;coldfusion&quot;, &quot;javascript&quot;, &quot;asp&quot;, &quot;ruby&quot;] });</code></pre>
194</dd>
195
196
197<dt>
198 Get or set the <code>source</code> option, after init.
199</dt>
200<dd>
201<pre><code>//getter
202var source = $('.selector').autocomplete('option', 'source');
203//setter
204$('.selector').autocomplete('option', 'source', [&quot;c++&quot;, &quot;java&quot;, &quot;php&quot;, &quot;coldfusion&quot;, &quot;javascript&quot;, &quot;asp&quot;, &quot;ruby&quot;]);</code></pre>
205</dd>
206
207 </dl>
208 </div>
209</li>
210
211 </ul>
212 </div>
213 <div id="events">
214 <h2 class="top-header">Events</h2>
215 <ul class="events-list">
216
217<li class="event" id="event-search">
218 <div class="event-header">
219 <h3 class="event-name"><a href="#event-search">search</a></h3>
220 <dl>
221 <dt class="event-type-label">Type:</dt>
222 <dd class="event-type">autocompletesearch</dd>
223 </dl>
224 </div>
225 <div class="event-description">
226 <p>Before a request (source-option) is started, after minLength and delay are met. Can be cancelled (return false), then no request will be started and no items suggested.</p>
227 </div>
228 <div class="event-examples">
229 <h4>Code examples</h4>
230 <dl class="event-examples-list">
231
232<dt>
233 Supply a callback function to handle the <code>search</code> event as an init option.
234</dt>
235<dd>
236<pre><code>$('.selector').autocomplete({
237 search: function(event, ui) { ... }
238});</code></pre>
239</dd>
240
241
242<dt>
243 Bind to the <code>search</code> event by type: <code>autocompletesearch</code>.
244</dt>
245<dd>
246<pre><code>$('.selector').bind('autocompletesearch', function(event, ui) {
247 ...
248});</code></pre>
249</dd>
250
251 </dl>
252 </div>
253</li>
254
255
256<li class="event" id="event-open">
257 <div class="event-header">
258 <h3 class="event-name"><a href="#event-open">open</a></h3>
259 <dl>
260 <dt class="event-type-label">Type:</dt>
261 <dd class="event-type">autocompleteopen</dd>
262 </dl>
263 </div>
264 <div class="event-description">
265 <p>After a request with the data ready, before it is actually displayed; also indicates the suggestion menu will be opened.</p>
266 </div>
267 <div class="event-examples">
268 <h4>Code examples</h4>
269 <dl class="event-examples-list">
270
271<dt>
272 Supply a callback function to handle the <code>open</code> event as an init option.
273</dt>
274<dd>
275<pre><code>$('.selector').autocomplete({
276 open: function(event, ui) { ... }
277});</code></pre>
278</dd>
279
280
281<dt>
282 Bind to the <code>open</code> event by type: <code>autocompleteopen</code>.
283</dt>
284<dd>
285<pre><code>$('.selector').bind('autocompleteopen', function(event, ui) {
286 ...
287});</code></pre>
288</dd>
289
290 </dl>
291 </div>
292</li>
293
294
295<li class="event" id="event-focus">
296 <div class="event-header">
297 <h3 class="event-name"><a href="#event-focus">focus</a></h3>
298 <dl>
299 <dt class="event-type-label">Type:</dt>
300 <dd class="event-type">autocompletefocus</dd>
301 </dl>
302 </div>
303 <div class="event-description">
304 <p>Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item. Cancelling this event prevents the value from being updated, but does not prevent the menu item from being focused.</p>
305 </div>
306 <div class="event-examples">
307 <h4>Code examples</h4>
308 <dl class="event-examples-list">
309
310<dt>
311 Supply a callback function to handle the <code>focus</code> event as an init option.
312</dt>
313<dd>
314<pre><code>$('.selector').autocomplete({
315 focus: function(event, ui) { ... }
316});</code></pre>
317</dd>
318
319
320<dt>
321 Bind to the <code>focus</code> event by type: <code>autocompletefocus</code>.
322</dt>
323<dd>
324<pre><code>$('.selector').bind('autocompletefocus', function(event, ui) {
325 ...
326});</code></pre>
327</dd>
328
329 </dl>
330 </div>
331</li>
332
333
334<li class="event" id="event-select">
335 <div class="event-header">
336 <h3 class="event-name"><a href="#event-select">select</a></h3>
337 <dl>
338 <dt class="event-type-label">Type:</dt>
339 <dd class="event-type">autocompleteselect</dd>
340 </dl>
341 </div>
342 <div class="event-description">
343 <p>Triggered when an item is selected from the menu; ui.item refers to the selected item. The default action of select is to replace the text field's value with the value of the selected item. Cancelling this event prevents the value from being updated, but does not prevent the menu from closing.</p>
344 </div>
345 <div class="event-examples">
346 <h4>Code examples</h4>
347 <dl class="event-examples-list">
348
349<dt>
350 Supply a callback function to handle the <code>select</code> event as an init option.
351</dt>
352<dd>
353<pre><code>$('.selector').autocomplete({
354 select: function(event, ui) { ... }
355});</code></pre>
356</dd>
357
358
359<dt>
360 Bind to the <code>select</code> event by type: <code>autocompleteselect</code>.
361</dt>
362<dd>
363<pre><code>$('.selector').bind('autocompleteselect', function(event, ui) {
364 ...
365});</code></pre>
366</dd>
367
368 </dl>
369 </div>
370</li>
371
372
373<li class="event" id="event-close">
374 <div class="event-header">
375 <h3 class="event-name"><a href="#event-close">close</a></h3>
376 <dl>
377 <dt class="event-type-label">Type:</dt>
378 <dd class="event-type">autocompleteclose</dd>
379 </dl>
380 </div>
381 <div class="event-description">
382 <p>When the list is hidden - doesn't have to occur together with a change.</p>
383 </div>
384 <div class="event-examples">
385 <h4>Code examples</h4>
386 <dl class="event-examples-list">
387
388<dt>
389 Supply a callback function to handle the <code>close</code> event as an init option.
390</dt>
391<dd>
392<pre><code>$('.selector').autocomplete({
393 close: function(event, ui) { ... }
394});</code></pre>
395</dd>
396
397
398<dt>
399 Bind to the <code>close</code> event by type: <code>autocompleteclose</code>.
400</dt>
401<dd>
402<pre><code>$('.selector').bind('autocompleteclose', function(event, ui) {
403 ...
404});</code></pre>
405</dd>
406
407 </dl>
408 </div>
409</li>
410
411
412<li class="event" id="event-change">
413 <div class="event-header">
414 <h3 class="event-name"><a href="#event-change">change</a></h3>
415 <dl>
416 <dt class="event-type-label">Type:</dt>
417 <dd class="event-type">autocompletechange</dd>
418 </dl>
419 </div>
420 <div class="event-description">
421 <p>After an item was selected; ui.item refers to the selected item. Always triggered after the close event.</p>
422 </div>
423 <div class="event-examples">
424 <h4>Code examples</h4>
425 <dl class="event-examples-list">
426
427<dt>
428 Supply a callback function to handle the <code>change</code> event as an init option.
429</dt>
430<dd>
431<pre><code>$('.selector').autocomplete({
432 change: function(event, ui) { ... }
433});</code></pre>
434</dd>
435
436
437<dt>
438 Bind to the <code>change</code> event by type: <code>autocompletechange</code>.
439</dt>
440<dd>
441<pre><code>$('.selector').bind('autocompletechange', function(event, ui) {
442 ...
443});</code></pre>
444</dd>
445
446 </dl>
447 </div>
448</li>
449
450 </ul>
451 </div>
452 <div id="methods">
453 <h2 class="top-header">Methods</h2>
454 <ul class="methods-list">
455
456<li class="method" id="method-destroy">
457 <div class="method-header">
458 <h3 class="method-name"><a href="#method-destroy">destroy</a></h3>
459 <dl>
460 <dt class="method-signature-label">Signature:</dt>
461 <dd class="method-signature">.autocomplete( 'destroy'
462
463
464
465
466
467
468
469)</dd>
470 </dl>
471 </div>
472 <div class="method-description">
473 <p>Remove the autocomplete functionality completely. This will return the element back to its pre-init state.</p>
474 </div>
475</li>
476
477
478<li class="method" id="method-disable">
479 <div class="method-header">
480 <h3 class="method-name"><a href="#method-disable">disable</a></h3>
481 <dl>
482 <dt class="method-signature-label">Signature:</dt>
483 <dd class="method-signature">.autocomplete( 'disable'
484
485
486
487
488
489
490
491)</dd>
492 </dl>
493 </div>
494 <div class="method-description">
495 <p>Disable the autocomplete.</p>
496 </div>
497</li>
498
499
500<li class="method" id="method-enable">
501 <div class="method-header">
502 <h3 class="method-name"><a href="#method-enable">enable</a></h3>
503 <dl>
504 <dt class="method-signature-label">Signature:</dt>
505 <dd class="method-signature">.autocomplete( 'enable'
506
507
508
509
510
511
512
513)</dd>
514 </dl>
515 </div>
516 <div class="method-description">
517 <p>Enable the autocomplete.</p>
518 </div>
519</li>
520
521
522<li class="method" id="method-option">
523 <div class="method-header">
524 <h3 class="method-name"><a href="#method-option">option</a></h3>
525 <dl>
526 <dt class="method-signature-label">Signature:</dt>
527 <dd class="method-signature">.autocomplete( 'option'
528
529, optionName
530
531, <span class="optional">[</span>value<span class="optional">] </span>
532
533
534
535)</dd>
536 </dl>
537 </div>
538 <div class="method-description">
539 <p>Get or set any autocomplete option. If no value is specified, will act as a getter.</p>
540 </div>
541</li>
542
543
544<li class="method" id="method-search">
545 <div class="method-header">
546 <h3 class="method-name"><a href="#method-search">search</a></h3>
547 <dl>
548 <dt class="method-signature-label">Signature:</dt>
549 <dd class="method-signature">.autocomplete( 'search'
550
551, <span class="optional">[</span>value<span class="optional">] </span>
552
553
554
555
556
557)</dd>
558 </dl>
559 </div>
560 <div class="method-description">
561 <p>Triggers a search event, which, when data is available, then will display the suggestions; can be used by a selectbox-like button to open the suggestions when clicked. If no value argument is specified, the current input's value is used. Can be called with an empty string and minLength: 0 to display all items.</p>
562 </div>
563</li>
564
565
566<li class="method" id="method-close">
567 <div class="method-header">
568 <h3 class="method-name"><a href="#method-close">close</a></h3>
569 <dl>
570 <dt class="method-signature-label">Signature:</dt>
571 <dd class="method-signature">.autocomplete( 'close'
572
573
574
575
576
577
578
579)</dd>
580 </dl>
581 </div>
582 <div class="method-description">
583 <p>Close the autocomplete menu. Useful in combination with the search method, to close the open menu.</p>
584 </div>
585</li>
586
587 </ul>
588 </div>
589 <div id="theming">
590 <h2 class="top-header">Theming</h2>
591 <p>The jQuery UI Autocomplete plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
592</p>
593 <p>If a deeper level of customization is needed, there are widget-specific classes referenced within the ui.autocomplete.css stylesheet that can be modified. These classes are highlighed in bold below.
594</p>
595
596 <h3>Sample markup with jQuery UI CSS Framework classes</h3>
597 &lt;input class=&quot;<strong>ui-autocomplete</strong>&quot;/&gt;
598 <p class="theme-note">
599 <strong>
600 Note: This is a sample of markup generated by the autocomplete plugin, not markup you should use to create a autocomplete. The only markup needed for that is &lt;input/&gt;.
601 </strong>
602 </p>
603
604 </div>
605</div>
606
607</p><!--
608Pre-expand include size: 25368 bytes
609Post-expand include size: 42213 bytes
610Template argument size: 24687 bytes
611Maximum: 2097152 bytes
612-->
613
614<!-- Saved in parser cache with key jqdocs_docs:pcache:idhash:3766-1!1!0!!en!2 and timestamp 20100128052926 -->
Note: See TracBrowser for help on using the repository browser.