Fixes Issue 0024574: Filter is not working fine in some special cases
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Mon, 26 Aug 2013 17:44:12 +0530
changeset 21018 b15fbad4f98e
parent 21017 5adbb7012852
child 21019 327ce5aac264
Fixes Issue 0024574: Filter is not working fine in some special cases

When list items are filtered by selecting the option from dropdown, the filter applied is filtering using contains. Hence if the filter is 'test A', 'test B A' will also be shown.
When selecting values, == is appended to each selected item to filter the exact value.
When showing picklist, == is trimmed from value so that the values are selected properly in the dropdown.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js	Fri Aug 23 07:01:49 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js	Mon Aug 26 17:44:12 2013 +0530
@@ -49,9 +49,18 @@
   selectDefaultItem: function () {},
 
   showPickList: function () {
-    var ret = this.Super('showPickList', arguments);
-
-    this.selectItemFromValue(this.getValue());
+    var ret = this.Super('showPickList', arguments),
+        value, i;
+    //remove double equals symbol used for filtering purposes, so that the appropriate item is selected.
+    value = this.getValue();
+    if (value && value.length > 0) {
+      for (i = 0; i < value.length; i++) {
+        if (value[i].indexOf("==") === 0) {
+          value[i] = value[i].substring(2, value[i].length);
+        }
+      }
+    }
+    this.selectItemFromValue(value);
   },
 
   // note: can't override changed as it is used by the filter editor 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list.js	Fri Aug 23 07:01:49 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list.js	Mon Aug 26 17:44:12 2013 +0530
@@ -66,12 +66,19 @@
 
   // is overridden to keep track that a value has been explicitly picked
   pickValue: function (value) {
+    var i;
     this._pickedValue = true;
     // force the update of the list
     // if the user has entered with the keyboard the exact content of a list option,
     // its callout would not be called because the change would not be detected
     // see issue https://issues.openbravo.com/view.php?id=21491
     this._value = (this.value) ? this._value.concat(Math.random()) : Math.random();
+    //adding double equals to filter the exact value and not all matching sub strings. Refer issue https://issues.openbravo.com/view.php?id=24574.
+    if (value) {
+      for (i = 0; i < value.length; i++) {
+        value[i] = "==" + value[i];
+      }
+    }
     this.Super('pickValue', arguments);
     delete this._pickedValue;
     if (this.moveFocusOnPickValue && this.form.focusInNextItem) {