From version < 48.1 >
edited by Sergiu Dumitriu
on 2012/08/06
To version < 49.1 >
edited by Sergiu Dumitriu
on 2012/08/06
< >
Change comment: Fixed migrated syntax, updated scm link

Summary

Details

Page properties
Content
... ... @@ -1,28 +1,25 @@
1 -{{velocity filter="none"}}
2 -{{html clean="false" wiki="true"}}
1 +{{velocity}}
3 3  ##
4 4  ## TODO:
5 5  ## - Document the REST usage of the suggest (this is the recommanded way of using the suggest now - when possible)
6 6  ## - Merge the example document in this one (why are there 2 documents ?)
7 -## - Migrate this page to syntax 2.0
8 8  ##
9 -#startfloatingbox()
10 -**Contents**
7 +{{box cssClass="floatinginfobox" title="**Contents**"}}
8 +{{toc/}}
9 +{{/box}}
11 11  
12 -{{toc start="2" depth="2" numbered=""/}}
13 -#endfloatingbox()
14 -<p/>
15 15  {{info}}This is a Javascript widget bundled by default with the XWiki platform.{{/info}}
16 16  
17 17  == Usage ==
18 18  
19 -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.
15 +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, data retrieved from a custom document or a REST resource, or any custom information you provide.
20 20  
21 21  === Suggest fields from a class defined in the wiki ===
22 22  
23 -Use information from a predefined class in your wiki (e.g. **XWiki.TagClass**, **XWiki.XWikiUsers**, etc.) or from a class defined by yourself.
19 +Use information from a predefined class in your wiki (e.g. ##XWiki.TagClass##, ##XWiki.XWikiUsers##, etc.) or from a class defined by yourself.
20 +
24 24  For example, use **XWiki.TagClass** to suggest tags from the wiki tag cloud:
25 -<p/>
22 +
26 26  [[image:[email protected]]]
27 27  
28 28  {{code}}
... ... @@ -33,7 +33,7 @@
33 33  </form>
34 34  {{/code}}
35 35  
36 -The **JavascriptExtension** object from the **DevGuide.AutoSuggestWidgetExample** page contains the Javascript code to enable the widget when focusing on the text field:
33 +The ##JavascriptExtension## object from the [[DevGuide.AutoSuggestWidgetExample]] page contains the Javascript code to enable the widget when focusing on the text field:
37 37  
38 38  {{code}}
39 39  (function(){
... ... @@ -41,7 +41,7 @@
41 41   if($('myinput')) {
42 42   Event.observe($('myinput'), "focus", function() {
43 43   new XWiki.widgets.Suggest(this, {
44 - script: '$xwiki.getURL("${doc.space}.WebHome", "view")?xpage=suggest&classname=XWiki.TagClass&fieldname=tags&secCol=-&',
41 + script: '$xwiki.getURL("${doc.space}.WebHome", "view")?xpage=suggest&classname=XWiki.TagClass&fieldname=tags&secCol=-&',
45 45   varname: "input",
46 46   seps: " ,|",
47 47   offsety: 13
... ... @@ -52,10 +52,10 @@
52 52  })();
53 53  {{/code}}
54 54  
55 -==== Options used in the **suggest.vm** template: ====
52 +==== Options used in the ##suggest.vm## template: ====
56 56  
57 57  |=Option|=Details
58 -|xpage|Must use **xpage=suggest** because suggest.vm template is used to manage the request.
55 +|xpage|For class properties use ##xpage=suggest## because the ##suggest.vm## template can handle such requests.
59 59  |classname|The name of the class for the elements of the suggest list.
60 60  |fieldname|The field name from the class considered for the suggest list.
61 61  |firCol|First column of the list of results.
... ... @@ -63,19 +63,18 @@
63 63  
64 64  ==== Example ====
65 65  
66 -* Check out the example for class field values at [[Class Field Example>>DevGuide.AutoSuggestWidgetExample]]
63 +Check out the example for class field values at [[Class Field Example>>DevGuide.AutoSuggestWidgetExample]]
67 67  
68 68  === Suggest custom information ===
69 69  
70 -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 the **get** action and with **outputSyntax=plain** parameter in the url, eg: //xwiki/bin/get/Space/Page?outputSyntax=plain//) that maps your results to the **xml** input accepted by the **autosuggest** class.
71 -For example, you can build a list of suggestions that contains the wiki page names within a certain space:
72 -<p/>
67 +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 the ##get## action and with ##outputSyntax=plain## parameter in the url, for example: ##xwiki/bin/get/Space/Page?outputSyntax=plain##) that maps your results to the **xml** input accepted by the widget. For example, you can build a list of suggestions that contains the wiki page names within a certain space:
68 +
73 73  [[image:[email protected]]]
74 74  
75 75  {{code}}
76 76  $!xwiki.jsx.use("DevGuide.AjaxSuggestCustomExample")
77 77  <form method="post" action="#">
78 - <label for="myinput">Type the name of an example page from the *DevGuide* space and test the suggest list:</label>
74 + <label for="myinput">Type the name of an example page from the <tt>DevGuide</tt> space and test the suggest list:</label>
79 79   <input id="myinput_suggest" size="20" type="text" value=""/>
80 80   <input id="myinput" type="hidden" />
81 81   <input id="mybutton" type="button" value="Go" /><br/>
... ... @@ -82,7 +82,7 @@
82 82  </form>
83 83  {{/code}}
84 84  
85 -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.
81 +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.
86 86  
87 87  {{code}}
88 88  (function(){
... ... @@ -90,9 +90,9 @@
90 90   if($('myinput_suggest')) {
91 91   Event.observe($('myinput_suggest'), "focus", function() {
92 92   new XWiki.widgets.Suggest(this, {
93 - script: "$xwiki.getURL("DevGuide.SuggestService", "get", "outputSyntax=plain&spacename=DevGuide")&",
94 - varname: "input",
95 - seps: " ,|",
89 + script: "$xwiki.getURL('DevGuide.SuggestService', 'get', 'outputSyntax=plain&spacename=DevGuide')&",
90 + varname: "input",
91 + seps: " ,|",
96 96   offsety: 13,
97 97   minchars: 3
98 98   });
... ... @@ -102,7 +102,7 @@
102 102  })();
103 103  {{/code}}
104 104  
105 -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.
101 +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 an **xml** file that has ##<results>## as a root node and ##<rs>## as children.
106 106  
107 107  {{code}}
108 108  ##
... ... @@ -130,8 +130,8 @@
130 130  </results>
131 131  {{/code}}
132 132  
133 -To provide autosuggest to several elements on the form, you can use JavaScript to loop through all the form elements and provide autosuggest if they meet certain conditions. In the example below, if there are form elements with id 'Supplier' in the 'inline' form, they get assigned an autosuggest that uses the Suppliers space as its source. If the element id matches 'Product' the autosuggest is told to use the 'Products' space as it's source instead.
134 -<p/>
129 +To provide autosuggest to several elements on the form, you can use JavaScript to loop through all the form elements and provide autosuggest if they meet certain conditions. In the example below, if there are form elements with id //Supplier// in the form, they get assigned a suggest widget that uses the //Suppliers// space as its source. If the element id matches //Product//, the suggest is told to use the //Products// space as it's source instead.
130 +
135 135  This method can be very useful when a form contains a lot of similar elements that require autosuggest. If you make sure the naming is done consistently, you can also use javascript to assign autosuggest based on part of the element id, for example 'all elements ending with _foo' or 'all elements starting with Bar_'. You can use the velocity code from the example above with the code below.
136 136  
137 137  {{code}}
... ... @@ -152,9 +152,9 @@
152 152  function mySuggest(element, space) {
153 153   if (!element.suggest) {
154 154   element.suggest = new XWiki.widgets.Suggest(element, {
155 - script: "$xwiki.getURL("Sandbox.AutoSuggest", "get")"+ "?outputSyntax=plain&spacename="+space+"&",
156 - varname: "input",
157 - seps: " ,|",
151 + script: "$xwiki.getURL('Sandbox.AutoSuggest', 'get', 'outputSyntax=plain&spacename=')"+space+"&",
152 + varname: "input",
153 + seps: " ,|",
158 158   offsety: 13,
159 159   minchars: 1
160 160   });
... ... @@ -169,13 +169,15 @@
169 169  === Suggest Users or Groups from the wiki ===
170 170  
171 171  Local or global users and groups from the wiki can be suggested using the **uorgsuggest.vm** template.
172 -<p/>
168 +
173 173  Example:
174 -<p/>
170 +
171 +{{code}}
175 175  $xwiki.jsx.use("$doc.fullName")##
176 176  
177 177  <input name="userInput" id="userInput" value="" type="text"/>
178 -<p/>
175 +{{/code}}
176 +
179 179  Here is the code that made the suggestion of global users from the wiki possible:
180 180  
181 181  {{code}}
... ... @@ -203,31 +203,31 @@
203 203  })();
204 204  {{/code}}
205 205  
206 -== Javascript parameters for the **ajaxsuggest** class ==
204 +== Javascript parameters for the ##XWiki.widgets.Suggest## constructor ==
207 207  
208 208  |=Parameter|=Details
209 209  |minchars|The minimum number of characters after which to trigger the suggest. Default value is 1.
210 210  |get|The HTTP method for the AJAX request.
211 -|varname|The name of the request parameter holding the input stub. Default value is **input**.
212 -|className|The CSS classname of the suggest list. Default value is **ajaxsuggest**.
213 -|timeout|Default value is **2500**.
214 -|delay|Default value is **500**.
215 -|offsety|Default value is **-5**.
209 +|varname|The name of the request parameter holding the input stub. Default value is ##input##.
210 +|className|The CSS classname of the suggest list. Default value is ##ajaxsuggest##.
211 +|timeout|Default value is ##2500##.
212 +|delay|Default value is ##500##.
213 +|offsety|Default value is ##-5##.
216 216  |shownoresults|Display a "no results" message, or simply hide the suggest box when no suggestions are available.
217 -|noresults|Default displayed message is **No results!**.
218 -|maxheight|Default value is **250**.
219 -|cache|Default value is **false**.
215 +|noresults|Default displayed message is ##No results!##.
216 +|maxheight|Default value is ##250##.
217 +|cache|Default value is ##false##.
220 220  |seps|Default value is "".
221 -|resultsParameter|The name of the JSON variable or XML element holding the results.Default value is **results** for the old suggest, **searchResults** for the REST search.
222 -|resultId|The name of the JSON parameter or XML attribute holding the result identifier. DEfault value is **id** for both the old suggest and the REST search.
223 -|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.
224 -|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.
225 -|parentContainer|The id of the element that will hold the suggest element. Default value is **body**.
226 -|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.
219 +|resultsParameter|The name of the JSON variable or XML element holding the results.Default value is ##results## for the old suggest, ##searchResults## for the REST search.
220 +|resultId|The name of the JSON parameter or XML attribute holding the result identifier. DEfault value is ##id## for both the old suggest and the REST search.
221 +|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.
222 +|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.
223 +|parentContainer|The id of the element that will hold the suggest element. Default value is ##body##.
224 +|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.
227 227  
228 228  == Tips ==
229 229  
230 -* Suggest event: **xwiki:suggest:selected**
228 +* Suggest event: ##xwiki:suggest:selected##
231 231  
232 232  {{code}}
233 233  Event.observe($('myInput'), "xwiki:suggest:selected", function(event) {
... ... @@ -237,12 +237,10 @@
237 237  
238 238  * Check out the code:
239 239  ** for your wiki instance: **{{{http://localhost:8080/xwiki/resources/js/xwiki/suggest/ajaxSuggest.js}}}**.
240 -** the suggest resources on svn(for exemple tag xwiki-web-2.2): [[http://svn.xwiki.org/svnroot/xwiki/platform/web/tags/xwiki-web-2.2/standard/src/main/webapp/resources/js/xwiki/suggest/]]
238 +** the suggest resources on GitHub(for exemple tag xwiki-platform-4.1): {{scm branch="xwiki-platform-4.1" path="xwiki-platform-core/xwiki-platform-web/src/main/webapp/resources/uicomponents/suggest/" /}}
241 241  
242 242  == Bugs we know about ==
243 243  
244 244  * The suggest feature will not work if the page called by the widget is not saved with programming rights: see details on [[http://jira.xwiki.org/jira/browse/XE-539]].
245 -<p/>
246 246  
247 -{{/html}}
248 248  {{/velocity}}

Get Connected