Author: musachy
Date: Thu May 31 18:55:37 2007
New Revision: 543354
URL: http://svn.apache.org/viewvc?view=rev&rev=543354
Log:
WW-1945 add a method(javascript) to set the selected value to the autocompleter
methods added to the autocompleter widget:
* setSelectedKey(key)
* setSelectedValue(value)
* getSelectedKey()
* getSelectedValue()
* getText()
Modified:
struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java
struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js
struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js
struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts_dojo.js.uncompressed.js
Modified:
struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java?view=diff&rev=543354&r1=543353&r2=543354
==============================================================================
---
struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java
(original)
+++
struts/struts2/trunk/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Autocompleter.java
Thu May 31 18:55:37 2007
@@ -117,6 +117,40 @@
* <sx:autocompleter href="%{jsonList}" formId="selectForm"
listenTopics="/changed"/>
* </pre>
* <!-- END SNIPPET: example4 -->
+ *
+ * <!-- START SNIPPET: example5 -->
+ * <p>Set/Get selected values using JavaScript</p>
+ * <pre>
+ * <sx:autocompleter href="%{jsonList}" id="auto"/>
+ * <script type="text/javascript">
+ * function getValues() {
+ * var autoCompleter = dojo.widget.byId("auto");
+ *
+ * //key (in the states example above, "AL")
+ * var key = autoCompleter.getSelectedKey();
+ * alert(key);
+ *
+ * //value (in the states example above, "Alabama")
+ * var value = autoCompleter.getSelectedValue();
+ * alert(value);
+ *
+ * //text currently on the textbox (anything the user typed)
+ * var text = autoCompleter.getText();
+ * alert(text);
+ * }
+ *
+ * function setValues() {
+ * var autoCompleter = dojo.widget.byId("auto");
+ *
+ * //key (key will be set to "AL" and value to "Alabama")
+ * autoCompleter.setSelectedKey("AL");
+ *
+ * //value (key will be set to "AL" and value to "Alabama")
+ * autoCompleter.setSelectedValue("Alabama");
+ * }
+ * </script>
+ * </pre>
+ * <!-- START SNIPPET: example5 -->
*/
@StrutsTag(name="autocompleter",
tldTagClass="org.apache.struts2.dojo.views.jsp.ui.AutocompleterTag",
description="Renders a combobox with autocomplete and AJAX capabilities")
public class Autocompleter extends ComboBox {
Modified:
struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js?view=diff&rev=543354&r1=543353&r2=543354
==============================================================================
---
struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js
(original)
+++
struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js
Thu May 31 18:55:37 2007
@@ -476,5 +476,39 @@
else {
this._startSearch(searchStr);
}
+ },
+
+ setSelectedKey : function(key) {
+ var data = this.dataProvider.data;
+ for(element in data) {
+ var obj = data[element];
+ if(obj[1].toString() == key) {
+ this.setValue(obj[0].toString());
+ this.comboBoxSelectionValue.value = obj[1].toString();
+ }
+ }
+ },
+
+ getSelectedKey : function() {
+ return this.comboBoxSelectionValue.value;
+ },
+
+ setSelectedValue : function(text) {
+ var data = this.dataProvider.data;
+ for(element in data) {
+ var obj = data[element];
+ if(obj[0].toString() == text) {
+ this.setValue(obj[0].toString());
+ this.comboBoxSelectionValue.value = obj[1].toString();
+ }
+ }
+ },
+
+ getSelectedValue : function() {
+ return this.comboBoxValue.value;
+ },
+
+ getText : function() {
+ return this.textInputNode.value();
}
});