The example at
http://alloy.liferay.com/demos.php?demo=autocomplete is good but uses a local variable as the datasource. I've been looking for an example that shows how to use AUI.AutoComplete that fetches (json) data from a database through ajax but no luck so far...
So, now I'm turning to the great Liferay community

My code (which doesn't work for browsers other than Firefox):
1 window.AC = new A.AutoComplete(
2 {
3 dataSource: function(request) {
4 var items = null;
5 resUrl.setResourceId("depositSearch");
6 resUrl.setParameter('search',A.one('#<portlet:namespace/>_searchField').get('value'));
7 A.io.request(resUrl.toString(), {
8 cache: true,
9 sync: true,
10 timeout: 1000,
11 dataType: 'json',
12 method: 'get',
13 on: {
14 success: function() {
15 items = this.get('responseData');
16 },
17 failure: function() {
18 }
19 }
20 });
21
22 return items;
23 },
24 dataSourceType: 'Function',
25 schema: {
26 metaFields: {javaClass:"javaClass"},
27 resultListLocator: "list",
28 resultFields: ['id', 'name']
29 },
30 schemaType: 'json',
31 forceSelection: true,
32 autoHighlight: false,
33 matchKey: 'id',
34 queryDelay: 0.5,
35 typeAhead: true,
36 contentBox: '#myContainer',
37 input: '#<portlet:namespace/>_searchField'
38 }
39 );
The above works in Firefox. For other browsers, I can see in the logs that calls are made and the results are properly created at the server-side. Internet Explorer 8 fetches
and displays the results if I leave the searchbox empty ...
I created a
jira ticket for this but am not sure if it's really a bug or just me doing something wrong.
I seem to recall reading something about YUI and problems with synchronous calls
sync: true. Maybe this is the reason? But with
sync:false, the above fails since
items (returned by the datasource function) will be null if not waiting for the data to arrive.
Hopefully, someone has got a solution to this, perhaps using some predefined datasource rather than a function.
Any insight on this would be great!
Por favor, faça login para denunciar.