You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2007/04/29 20:47:32 UTC

svn commit: r533542 - /struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js

Author: musachy
Date: Sun Apr 29 11:47:31 2007
New Revision: 533542

URL: http://svn.apache.org/viewvc?view=rev&rev=533542
Log:
Improve how the autocompleter gets the data from the JSON response (backport from 2.1)

Modified:
    struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js

Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js?view=diff&rev=533542&r1=533541&r2=533542
==============================================================================
--- struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js (original)
+++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js Sun Apr 29 11:47:31 2007
@@ -69,24 +69,42 @@
         if(!this.firstRequest) {
           this.cbox.notify.apply(this.cbox, [data, type, evt]);
         }
+        var arrData = null;
+        var dataByName = data[this.cbox.dataFieldName];
         if(!dojo.lang.isArray(data)) {
            //if there is a dataFieldName, take it
-           if(!dojo.string.isBlank(this.cbox.dataFieldName) && data[this.cbox.dataFieldName] != null) {
-             arrData = data[this.cbox.dataFieldName];
+           if(dataByName) {
+             if(dojo.lang.isArray(dataByName)) {
+                //ok, it is an array
+                arrData = dataByName;
+             } else if(dojo.lang.isObject(dataByName)) {
+                //it is an object, treat it like a map
+                arrData = [];
+                for(var key in dataByName){
+                    arrData.push([dataByName[key], key]);
+                }
+             }
            } else {
              //try to find a match
-             var arrData = null;
+             var tmpArrData = [];
              for(var key in data){
                //does it start with the field name? take it
-               if(key == this.cbox.name) {
+               if(dojo.string.startsWith(key, this.cbox.name)) {
                  arrData = data[key];
                  break;
+               } else {
+                 //if nathing else is found, we will use values in this 
+                 //object as the data
+                 tmpArrData.push([data[key], key]);
                }
                //grab the first array found, we will use it if nothing else
                //is found
-               if(!arrData && dojo.lang.isArray(data[key])) {
-                 arrData = data = data[key];
+               if(!arrData && dojo.lang.isArray(data[key]) && !dojo.lang.isString(data[key])) {
+                 arrData = data[key];
                }
+             }
+             if(!arrData) {
+               arrData = tmpArrData;
              }
            }