Fixed issue 18134.Not filter by display field when clicking on the drop-down button.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Mon, 01 Aug 2011 11:40:01 +0200
changeset 13353 2e0d9e89d2af
parent 13352 6c17f2c86473
child 13354 a185170cc1bf
Fixed issue 18134.Not filter by display field when clicking on the drop-down button.
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-widget.js
--- a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-widget.js	Mon Aug 01 10:48:28 2011 +0200
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-widget.js	Mon Aug 01 11:40:01 2011 +0200
@@ -662,41 +662,49 @@
               this.selector.checkDefaultValidations(form, item);
             },
               getPickListFilterCriteria : function() {
-                var defValue, prop, i,
+                var defValue, i,
                     criteria = {
                       operator: 'or',
                       _constructor: 'AdvancedCriteria',
                       criteria:[]
-                    };
+                    },
+                    crit = this.Super('getPickListFilterCriteria');
 
                 criteria.criteria.push(isc.OBRestDataSource.getDummyCriterion());
 
                 // also adds the special ORG parameter
                 OB.Utilities.addFormInputsToCriteria(criteria);
 
-                criteria.criteria.push({
-                  fieldName: this.displayField,
-                  operator: 'iContains',
-                  value: this.getDisplayValue()
-                });
-
-
                 // adds the selector id to filter used to get filter information
                 criteria._selectorDefinitionId = this.selector.selectorDefinitionId;
 
-                // only filter if the display field is also
-                // passed
-                // the displayField filter is not passed when
-                // the user clicks the
-                // drop-down button
-                for (i = 0; i < this.selector.extraSearchFields.length; i++) {
-                  if (!criteria[this.selector.extraSearchFields[i]]) {
-                    criteria.criteria.push({
-                      fieldName: this.selector.extraSearchFields[i],
-                      operator: 'iContains',
-                      value: this.getDisplayValue()
-                    });
+                // only filter if the display field is also passed
+                // the displayField filter is not passed when the user clicks the drop-down button
+                var displayFieldValue = null;
+                if (crit.criteria) {
+                  for (i = 0; i < crit.criteria.length; i++) {
+                    if (crit.criteria[i].fieldName === this.displayField) {
+                      displayFieldValue = crit.criteria[i].value;
+                    }
                   }
+                } else if (crit[this.displayField]) {
+                  displayFieldValue = crit[this.displayField];
+                }
+                if (displayFieldValue !== null) {
+                  for (i = 0; i < this.selector.extraSearchFields.length; i++) {
+                    if (!criteria[this.selector.extraSearchFields[i]]) {
+                      criteria.criteria.push({
+                        fieldName: this.selector.extraSearchFields[i],
+                        operator: 'iContains',
+                        value: displayFieldValue
+                      });
+                    }
+                  }
+                  criteria.criteria.push({
+                    fieldName: this.displayField,
+                    operator: 'iContains',
+                    value: displayFieldValue
+                  });
                 }
 
                 // for the suggestion box it is one big or