Changes for page Suggest Widget

Last modified by Marius Dumitru Florea on 2022/04/19

<
From version < 44.1 >
edited by Oana Florea
on 2010/09/13
To version < 45.2 >
edited by Vincent Massol
on 2010/12/12
>
Change comment: set title

Summary

Details

Page properties
Title
... ... @@ -1,0 +1,1 @@
1 +AutoSuggest Widget
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.OanaTabaranu
1 +XWiki.VincentMassol
Content
... ... @@ -4,8 +4,6 @@
4 4  ## - Merge the example document in this one (why are there 2 documents ?)
5 5  ## - Migrate this page to syntax 2.0
6 6  ##
7 -1 AutoSuggest Widget
8 -
9 9  #startfloatingbox()
10 10  *Contents*
11 11  #toc ("2" "2" "")
... ... @@ -133,7 +133,38 @@
133 133  </results>
134 134  {code}
135 135  
134 +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.
136 136  
136 +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.
137 +
138 +{code}
139 +(function(){
140 + document.observe('dom:loaded', function () {
141 + myForm = document.getElementById('inline').elements;
142 + for(i=0; i<myForm.length; i++){
143 + if(myForm[i].id =='Supplier'){
144 + mySuggest(myForm[i], 'Suppliers');
145 + }
146 + if(myForm[i].id=='Product'){
147 + mySuggest(myForm[i], 'Products');
148 + }
149 + }
150 + }); // end of doc observe
151 +})();
152 +
153 +function mySuggest(element, space) {
154 + if (!element.suggest) {
155 + element.suggest = new XWiki.widgets.Suggest(element, {
156 + script: "$xwiki.getURL("Sandbox.AutoSuggest", "view")"+ "?xpage=plain&spacename="+space+"&",
157 + varname: "input",
158 + seps: " ,|",
159 + offsety: 13,
160 + minchars: 1
161 + });
162 + }
163 +}
164 +{code}
165 +
137 137  1.1.1.1 Example
138 138  
139 139  * Check out the example for custom information at [Custom Information Example>DevGuide.AjaxSuggestCustomExample]

Get Connected