From version < 13.1 >
edited by ElenaOanaTabaranu
on 2009/07/17
To version < 14.1 >
edited by ElenaOanaTabaranu
on 2009/08/04
< >
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -13,7 +13,14 @@
13 13  
14 14  1.1 Usage
15 15  
16 -The suggest widget can be triggered when typing something in a text field. For example, it can suggest tags from the wiki tag cloud:
16 +The suggest widget can be triggered when typing something in a text field. The suggested list can contain field values from a class defined in your wiki or any custom information you provide.
17 +
18 +1.1.1 Suggest fields from a class defined in the wiki
19 +
20 +Use information from a predefined class in your wiki (e.g. *XWiki.TagClass*, *XWiki.XWikiUsers*, etc.) or from a class defined by yourself.
21 +For example, use *XWiki.TagClass* to suggest tags from the wiki tag cloud:
22 +
23 +For example, it can suggest tags from the wiki tag cloud:
17 17  {image:suggest.png|document=DevGuide.AutoSuggestWidget}
18 18  {code}
19 19  
... ... @@ -39,7 +39,56 @@
39 39  })();
40 40  {code}
41 41  
49 +1.1.1 Suggest custom information
42 42  
51 +When the information you want to suggest is not available through a class field or you generate it using a custom query, you need to create a service (plain wiki page called with *xpage=plain* parameter in the url) that maps your results to the *xml* input accepted by the *autosuggest* class.
52 +For example, you can build a list of suggestions that contains the wiki page names within a certain space:
53 +{code}
54 +
55 +$!xwiki.jsx.use("Tutorials.AjaxSuggestCustomExample")
56 +<form method="post" action="#">
57 + <label for="myinput">Type the name of an example page from the **DevGuide** space and test the suggest list:</label>
58 + <input id="myinput" size="20" type="text" value=""/>
59 +</form>
60 +
61 +{code}
62 +
63 +The *JavascriptExtension* object from the *DevGuide.AjaxSuggestCustomExample* page contains the Javascript code to enable the widget when focusing on the text field. Also, the *script* option uses the url for the results page.
64 +
65 +{code}
66 +(function(){
67 + document.observe('dom:loaded', function () {
68 + if($('myinput')) {
69 + Event.observe($('myinput'), "focus", function() {
70 + new ajaxSuggest(this, {script: "$xwiki.getURL("DevGuide.SuggestService", "view", "xpage=plain&spacename=Tutorials")&", varname: "input", seps: " ,|", offsety: 13});
71 + });
72 + }
73 + }); // end of doc observe
74 +})();
75 +{code}
76 +The service page uses a query to get all the pages from the space provided using *spacename* parameter in the url. The generated response must be a *xml* file that has *<results>* as a root node and *<rs>* as children.
77 +{code}
78 +##
79 +## Service to generate the suggest list of files from a certain space.
80 +## @spacename
81 +## @input
82 +##
83 +#set($input = $request.get("input").toLowerCase())
84 +#set($spacename = $request.get("spacename"))
85 +$response.setContentType("text/xml") ## generate a xml file
86 +## select pages
87 +#if("$!input" == "")
88 + #set($query = "select doc.name from XWikiDocument doc where doc.space='$spacename' and doc.name<>'WebHome' and doc.name<>'WebPreferences' order by doc.date desc")
89 +#else
90 + #set($query = "select doc.name from XWikiDocument doc where doc.space='$spacename' and doc.name<>'WebHome' and doc.name<>'WebPreferences' and lower(doc.name) like '%" + $input + "%' order by doc.date desc")
91 +#end
92 +#set($searchresults = $xwiki.search($query))
93 +<results space="$spacename">
94 + #foreach($result in $searchresults)
95 + <rs id="1" info="">$result</rs>
96 + #end
97 +</results>
98 +{code}
43 43  1.1 Javascript parameters for the *ajaxsuggest* class
44 44  
45 45  {table}
... ... @@ -61,7 +61,7 @@
61 61  resultValue|The name of the JSON parameter or XML attribute holding the result value.Default *value* for the old suggest, *pageFullName* for the REST page search.
62 62  resultInfo|The name of the JSON parameter or XML attribute holding the result auxiliary information. Default value is *info* for the old suggest, *pageFullName* for the REST search.
63 63  parentContainer|The id of the element that will hold the suggest element. Default value is *body*.
64 -script|Url to manage the ajax request.
120 +script|Url for the ajax request that will get the suggested list. Must end with *&* because *varname* parameter will be appended. Use *suggest.vm* to get field values from a wiki class or a custom url to generate the suggested list.
65 65  {table}
66 66  
67 67  1.1.1 Options for the *script* parameter:

Get Connected